- Python : 3.8.11
- OS : Ubuntu Kylin 20.04
- Conda : 4.10.1
- PyCharm : 2021.1.3 (Community Edition)
基础
代码
"""
@Author : 行初心
@Date : 8/6/21
"""
from tkinter import *
def main():
root = Tk()
w = Canvas(
root,
width=200,
height=200,
background="white"
)
w.pack()
w.create_line(0, 100, 200, 100, fill='yellow')
w.create_line(100, 0, 100, 200, fill='red', dash=(4, 4))
w.create_rectangle(50, 50, 150, 150, fill='blue')
mainloop()
if __name__ == '__main__':
main()
运行结果
变化
代码
"""
@Author : 行初心
@Date : 8/6/21
"""
from tkinter import *
def main():
root = Tk()
w = Canvas(
root,
width=200,
height=200,
background="white"
)
w.pack()
yellow_line = w.create_line(0, 100, 200, 100, fill='yellow')
red_line = w.create_line(100, 0, 100, 200, fill='red', dash=(4, 4))
blue_rect = w.create_rectangle(50, 50, 150, 150, fill='blue')
# 使用coords方法移动yellowLine线,移动到
w.coords(yellow_line,
0, 25, 100, 100)
# 使用itemconfig设置一个对象的属性值
w.itemconfig(blue_rect, fill='red')
# 矩形填充色变红了
# 使用delete方法删除red_line
w.delete(red_line)
mainloop()
if __name__ == '__main__':
main()
运行结果
参考资料
学习推荐
- Python文档 - English
- Python文档 - 中文
- Python规范 PEP
- Python规范 google版
- Python 源码
- Python PEP
- 优麒麟
- 掘金平台
- gitee平台
Python具有开源、跨平台、解释型和交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
GUI可以选择PyQt5、PySide2、wxPython、PyGObject、wxWidgets等进行创作。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。