这段代码在我这为什么一直报错啊?求各位大神解答一下
import tkinter as tkclass App:
def _init_(self,master):
frame = tk.Frame(master)
frame.pack()
self.hi_there = tk.Button(frame,text="打招呼",bg='black',fg="blue")
self.hi_there.pack()
root = tk.Tk()
app = App(root)
root.mainloop()
报错信息:Traceback (most recent call last):
File "C:\Users\25135\Desktop\tk2.py", line 9, in <module>
app = App(root)
TypeError: object() takes no parameters 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")
self.hi_there.pack()
root = tk.Tk()
app = App(root)
root.mainloop() 你的__init__写成_init_了,应该两边是两个下划线
页:
[1]