我正在学习Tkinter,在进入Tkinter之前,这个程序是我上一个项目的一部分。我想知道这个主菜单在Tkinter中的外观如何。
我试图寻找类似的东西,但当我参考主菜单时,我通常会将主菜单作为文件,编辑,查看,...
我的想法是,当您输入1 - 6时,您的窗口会被清除,其他信息会出现,并且有一个退出按钮和返回按钮。如果我不清楚请告诉我。英语不是我的母语所以......
print(" %s %s"%(nombre,apellido))
print(" __________________________________ ")
print(" | Menú principal |")
print(" | 1.Dato breve sobre mi carrera |")
print(" | 2.Cursos y tareas |")
print(" | 3.Grupos de apoyo |")
print(" | 4.Calendario Academico |")
print(" | 5.Feriados |")
print(" | 6.Salir |")
print(" |__________________________________|")
op=int(input(" Elija una opcion:"))
答案 0 :(得分:2)
我们走了。 如果这是你想要的,请接受它作为答案。
import tkinter as tk
class FirstFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
self.pack()
master.title("Menu")
master.geometry("500x400")
self.but1 = tk.Button(self, text= '1', command=self.opt1)
self.but1.pack()
self.but2 = tk.Button(self, text= '2', command=self.opt2)
self.but2.pack()
self.but3 = tk.Button(self, text= '3', command=self.opt3)
self.but3.pack()
self.but4 = tk.Button(self, text= '4', command=self.opt4)
self.but4.pack()
self.but5 = tk.Button(self, text= '5', command=self.opt5)
self.but5.pack()
self.but6 = tk.Button(self, text= '6', command=self.opt6)
self.but6.pack()
def opt1(self):
self.destroy()
self.app = SecondFrame(self.master)
def opt2(self):
self.destroy()
self.app = ThirdFrame(self.master)
def opt3(self):
self.destroy()
self.app = FourthFrame(self.master)
def opt4(self):
self.destroy()
self.app = FifthFrame(self.master)
def opt5(self):
self.destroy()
self.app = SixthFrame(self.master)
def opt6(self):
self.destroy()
self.app = SeventhFrame(self.master)
class SecondFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
self.pack()
master.title("Opt1")
master.geometry("400x400")
self.opt1lab = tk.Label(self, text = 'This is option 1')
self.opt1lab.pack()
self.gobackbut1 = tk.Button(self, text = 'Go Back', command = self.goback1)
self.gobackbut1.pack()
def goback1(self):
self.destroy()
self.app = FirstFrame(self.master)
class ThirdFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
self.pack()
master.title("Opt2")
master.geometry("400x400")
self.opt2lab = tk.Label(self, text = 'This is option 2')
self.opt2lab.pack()
self.gobackbut2 = tk.Button(self, text = 'Go Back', command = self.goback2)
self.gobackbut2.pack()
def goback2(self):
self.destroy()
self.app = FirstFrame(self.master)
class FourthFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
self.pack()
master.title("Opt3")
master.geometry("400x400")
self.opt3lab = tk.Label(self, text = 'This is option 3')
self.opt3lab.pack()
self.gobackbut3 = tk.Button(self, text = 'Go Back', command = self.goback3)
self.gobackbut3.pack()
def goback3(self):
self.destroy()
self.app = FirstFrame(self.master)
class FifthFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
self.pack()
master.title("Opt4")
master.geometry("400x400")
self.opt4lab = tk.Label(self, text = 'This is option 4')
self.opt4lab.pack()
self.gobackbut4 = tk.Button(self, text = 'Go Back', command = self.goback4)
self.gobackbut4.pack()
def goback4(self):
self.destroy()
self.app = FirstFrame(self.master)
class SixthFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
self.pack()
master.title("Opt5")
master.geometry("400x400")
self.opt5lab = tk.Label(self, text = 'This is option 5')
self.opt5lab.pack()
self.gobackbut5 = tk.Button(self, text = 'Go Back', command = self.goback5)
self.gobackbut5.pack()
def goback5(self):
self.destroy()
self.app = FirstFrame(self.master)
class SeventhFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
self.pack()
master.title("Opt6")
master.geometry("400x400")
self.opt6lab = tk.Label(self, text = 'This is option 6')
self.opt6lab.pack()
self.gobackbut6 = tk.Button(self, text = 'Go Back', command = self.goback6)
self.gobackbut6.pack()
def goback6(self):
self.destroy()
self.app = FirstFrame(self.master)
if __name__=="__main__":
root = tk.Tk()
app=FirstFrame(root)
root.mainloop()