我是 Python 新手,所以在制作了簡單的程式之后,我正在制作一個程式。使用 Tkinter,我設法創建了主螢屏和登錄螢屏(登錄表單 GUI)。但是,該功能有效,如果我不想登錄并單擊后退按鈕,它應該關閉登錄螢屏(登錄表單 GUI),但它會關閉整個程式。
我該如何避免呢?
這是我創建應用程式的方式。
class LoginFrame(ttk.Frame):
def __init__(self, container):
super().__init__(container)
self.__createMain__()
# Creates the widgets for the Main Screen
def __createMain__(self):
#Some Labels and entry buttons code
Button2 = Button(self, text='Close', command=self.Closes).place(x=200, y=140)
# Closes the main program
def Closes(self):
quit()
class Login(tk.Tk):
def __init__(self):
super().__init__()
self.title('Login Form')
self.geometry('350x300')
self.minsize(200,300)
self.maxsize(500,500)
self.__create_widgets()
def __create_widgets(self):
# create the input frame
First_Frame = LoginFrame(self)
First_Frame.place(height=200, width=700, x=20, y=20)
我通過命令將登錄類呼叫到我的主程式,它打開但我無法關閉它。我該怎么做?
uj5u.com熱心網友回復:
使用此代碼。
這將關閉完整的登錄螢屏。
class LoginFrame(ttk.Frame):
def __init__(self, container):
self.con = container
super().__init__(container)
self.__createMain__()
# Creates the widgets for the Main Screen
def __createMain__(self):
#Some Labels and entry buttons code
Button2 = Button(self, text='Close', command=self.Closes).place(x=200, y=140)
# Closes the main program
def Closes(self):
self.con.destroy()
class Login(tk.Tk):
def __init__(self):
super().__init__()
self.title('Login Form')
self.geometry('350x300')
self.minsize(200,300)
self.maxsize(500,500)
self.__create_widgets()
def __create_widgets(self):
# create the input frame
First_Frame = LoginFrame(self)
First_Frame.place(height=200, width=700, x=20, y=20)
但是,如果您想關閉 LoginFrame Only 則將關閉函式更改為此。
# Closes the main program
def Closes(self):
self.destroy()
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/529250.html
上一篇:Pythonmixins:呼叫super()時如何處理*args、**kwargs?
下一篇:代碼重構,在哪里實體化一個物件
