且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用类在 tkinter 画布上绘制多边形?

更新时间:2023-11-24 09:27:28

只是调用参数错误.

如果您想更改代码,此解决方案可以为您提供帮助.

If you want to change your code, this solution can help you.

类 GUI 只是继承自 Canvas,并没有实现任何东西.

Class GUI just inherits from Canvas and doesn't implement anything.

from Tkinter import*

root = Tk()

class GUI(Canvas):
    '''inherits Canvas class (all Canvas methodes, attributes will be accessible)
       You can add your customized methods here.
    '''
    def __init__(self,master,*args,**kwargs):
        Canvas.__init__(self, master=master, *args, **kwargs)

polygon = GUI(root)
polygon.create_polygon([150,75,225,0,300,75,225,150],     outline='gray', 
            fill='gray', width=2)

polygon.pack()
root.mainloop()

如需更多帮助,请添加评论.

For more help add comments.