0
我在Tkinter GUI的這個Python程序中遇到了一些與我的「BackButton」有關的問題。 MainFrame是一個包含動態內容的框架。
在兩個MenuPoints(設備配置和SCPI命令)中,我想實現一個BackButton,它將我帶回到前一個Frame/Window中,在這種情況下是MainFrame/MainMenu。我與SCPIMenu的主框架有點混淆,我在這裏輸入'???'。
有沒有任何想法如何實現這一點?謝謝你的時間。帶BackButton的Tkinter框架到MainMenu
class View(Tk):
def __init__(self):
Tk.__init__(self)
self.title('Device Configurator')
self.geometry('400x400')
self.resizable(0,0)
self.MainFrame = Frame(self, bd = '2', relief = RIDGE)
self.MainFrame.pack(expand = True, fill="both", padx = 5, pady = 20)
menubar = Menu(self)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label='Configure Devices', command = None)
filemenu.add_command(label='Exit', command=self.quit)
menubar.add_cascade(label='File', menu=filemenu)
infomenu = Menu(menubar, tearoff = 0)
infomenu.add_command(label='About', command = None)
menubar.add_cascade(label='Info', menu = infomenu)
self.config(menu = menubar)
def mainMenu(self):
configButton = Button(self.MainFrame, text = 'Device Configuration')
configButton.place(x=200, y=150,anchor=CENTER)
SCPIButton = Button(self.MainFrame, text = 'SCPI Command', command = self.SCPIMenu)
SCPIButton.place(x=200, y=200,anchor=CENTER)
def SCPIMenu(self):
self.SCPIFrame = Frame(???, bd = '2', relief = RIDGE)
self.SCPIFrame.pack(expand = True, fill="both", padx = 5, pady = 20)
BackButton = Button(???, text = 'Back', command = self.mainMenu)
BackButton.place(x=350, y=330, anchor=CENTER)
##The controller understands both the model and the view.
class Controller(object):
def __init__(self):
self.view = View()
self.view.mainMenu()
self.view.mainloop()
c = Controller()
你可能會看看這個問題隱藏部件(http://stackoverflow.com/q/3819354)。您可以在將屏幕視爲繪製屏幕的方法(並最終刪除之前的內容)或「框架」之間作出選擇,即在開始時填充,然後顯示或隱藏。後者得到了我的偏好(因爲它對我來說更多的是GUI /狀態,而不是程序方式,並且可能會限制依賴關係)。 – FabienAndre
當你最初按下「SCPI命令」按鈕時,你想要發生什麼?您是否希望將窗口的全部內容替換爲SCPIMenu框架,還是希望在單獨的彈出窗口或其他位置顯示該框架? –
我想用SCPIMenu框架替換窗口的全部內容,當我點擊後退按鈕時,我想回到主菜單,所以MainFrame。 – eljobso