0
我正在使用tkinter编写GUI,我希望窗口中的按钮以某种方式更改眼睛和脸部。我无法定义我的功能来更改圆圈和线条。我想我可以自己拨打create_line
来更改画布中的绘图。在我定义w
之后,我尝试将我的define
语句移动到我的程序底部,但没有运气。我得到的错误,如'App' object has no attribute 'create_line'
我是非常新的python,所以任何反馈将不胜感激。定义tkinter按钮命令来更改帧中的画布
# import tkinter
from tkinter import *
# define a new class
class App:
# define a command talk
def talk(self):
print("Talk button clicked...")
#w.self.create_line(45, 100, 90, 110)
# window of the GUI
def __init__(self, master):
# parent window
frame = Frame(master, bg = "#76F015")
# organizes the widgets into blocks
frame.pack()
# define a button in the parent window
self.button = Button(frame, text = "Talk", highlightbackground = "#D4D6D3",
fg = "black", command = self.talk)
self.button.pack(side = RIGHT)
# define a canvas
w = Canvas(frame, width = 125, height = 175, bg = "#76F015")
w.pack()
# draw a mouth
w.create_line(45, 100, 85, 100)
# run the main event loop
root = Tk()
app = App(root)
root.mainloop()
你需要说什么样的麻烦。你只用一个修改按钮就可以更好地进行实验。 REad https://stackoverflow.com/help/mcve –