|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import tkinter as tk
class App:
def __init__(self,master):
frame = tk.Frame(master)
frame.pack()
self.hi_there = tk.Button(frame,text="打招呼",bg='black',fg="blue",command=self.say_hi)
self.hi_there.pack()
def say_hi(self):
print("gcygucgcgw")
root = tk.Tk()
app = App(root)
root.mainloop()
报错信息:
Traceback (most recent call last):
File "Desktop\tk2(报错).py", line 17, in <module>
app = App(root)
File "Desktop\tk2.py", line 6, in __init__
self.hi_there = tk.Button(frame,text="打招呼",bg='black',fg="blue",command=self.say_hi)
AttributeError: 'App' object has no attribute 'say_hi'
- import tkinter as tk
- class App:
- def __init__(self,master):
- frame = tk.Frame(master)
- frame.pack()
- self.hi_there = tk.Button(frame,text="打招呼",bg='black',fg="blue",command=self.say_hi)
- self.hi_there.pack()
- def say_hi(self): # 这里要缩进,say_hi得在类里面
- print("gcygucgcgw")
- root = tk.Tk()
- app = App(root)
- root.mainloop()
复制代码
|
|