码迷,mamicode.com
首页 > 移动开发 > 详细

Python3 tkinter基础 Canvas coords 移动直线,itemconfig 设置矩形的颜色, delete 删除一条直线

时间:2018-10-01 20:42:03      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:emc   author   pack   create   思维   guid   开源   import   9.png   

?

  •                    python : 3.7.0
  •                           OS : Ubuntu 18.04.1 LTS
  •                          IDE : PyCharm 2018.2.4
  •                      conda : 4.5.11
  •            type setting : Markdown

?

基础

code

"""
@Author : 行初心
@Date   : 18-9-30
@Blog   : www.cnblogs.com/xingchuxin
@GitHub : github.com/GratefulHeartCoder
"""
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()

result

技术分享图片

?

code

"""
@Author : 行初心
@Date   : 18-9-30
@Blog   : www.cnblogs.com/xingchuxin
@GitHub : github.com/GratefulHeartCoder
"""
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))

    bule_rect = w.create_rectangle(50, 50, 150, 150, fill=‘blue‘)

    # 使用coords方法移动yellowLine线,移动到
    w.coords(yellow_line,
             0, 25, 100, 100)

    # 使用itemconfig设置一个对象的属性值
    w.itemconfig(bule_rect, fill=‘red‘)
    # 矩形填充色变红了

    # 使用delete方法删除readLine
    w.delete(red_line)

    mainloop()


if __name__ == ‘__main__‘:
    main()

result

技术分享图片

?

reference

  • [文档] https://docs.python.org/3/library/tkinter.html

?

resource

  • [文档] https://docs.python.org/3/
  • [规范] https://www.python.org/dev/peps/pep-0008/
  • [规范] https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules/
  • [源码] https://www.python.org/downloads/source/
  • [ PEP ] https://www.python.org/dev/peps/
  • [平台] https://www.cnblogs.com/

?


Python具有开源、跨平台、解释型和交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
GUI可以选择PyQt5、PySide2、wxPython、PyGObject、wxWidgets等进行创作。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。

Python3 tkinter基础 Canvas coords 移动直线,itemconfig 设置矩形的颜色, delete 删除一条直线

标签:emc   author   pack   create   思维   guid   开源   import   9.png   

原文地址:https://www.cnblogs.com/xingchuxin/p/9735540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!