为什么我的这行两行代码加入这个command之后,运行时的“确定”、“取消”按钮就消失了
self.btn1 = tk.Button(self, text='取消', command=self.btn1cal2())
self.btn1 = tk.Button(self, text='确定',command=self.btn1cal1())
下面是我的全部代码:
import tkinter as tk
class Window1(tk.Tk):
def __init__(self):
super().__init__()
self.title("0")
self.geometry('200x100+400+200')
self.resizable(False, False) # 窗口大小可调整=False
# self.protocol("WM_DELETE_WINDOW",True)
self.myinitgui()
def myinitgui(self): #创建用户界面
self.label1=tk.Label(self,text='是否关闭?') #标签A
self.label1.place(x=70,y=15) #放置
self.btn1 = tk.Button(self, text='取消', command=self.btn1cal2())
self.btn1.place(x=25, y=50, width=70, height=30)
self.btn1 = tk.Button(self, text='确定',command=self.btn1cal1())
self.btn1.place(x=100, y=50, width=70, height=30)
def btn1cal1(self):
i=0
while(i<10):
wrong=Wrong()
i=i+1
wrong.mainloop()
def btn1cal2(self):
i = 0
while (i < 10):
wrong = Wrong()
i = i + 1
wrong.mainloop()
class Wrong(tk.Tk):
def __init__(self):
super().__init__()
self.title("010")
height=random.randint(0,800)
width=random.randint(0,600)
self.geometry('200x100+%s+%s'%(height,width))
self.resizable(False, False) # 窗口大小可调整=False
self.label1 = tk.Label(self, text='程序一经启动将无法关闭!') # 标签A
self.label1.place(x=10, y=15) # 放置
if __name__=='__main__':
window1= Window1()
window1.mainloop()