0
晚上好!我试图弄清楚如何获得一个按钮,当点击后,打开另一个Gui文件夹中的另一个.py文件。 (我已经尝试了其他问题中给出的每个答案,这些答案可能会远程回答我的问题)。Tkinter Gui链接按钮到.py文件打开另一个Gui
enter code here
#this file is called main.py
from tkinter import *
root1 = Tk()
root1.title("ProQA-ish")
fphoto = PhotoImage(file="../icon/fireorig.png") #change wd to file named icon
fireButton = Button(root1, image=fphoto)
fireButton.config(height=228, width=200)
mphoto = PhotoImage(file="../icon/ems.png") #change wd to file named icon
emsButton = Button(root1, image=mphoto)
emsButton.config(height=224, width=197)
fireButton.pack(side=LEFT)
emsButton.pack(side=RIGHT)
root1.mainloop()
enter code here
#this is called emdmenu.py
from tkinter import *
root = Tk()
root.title("Emergency Medical Dispatch")
root.iconbitmap(default='../icon/fire.ico')
#----Window------
topframe = Frame(root)
topframe.pack()
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM)
#---Create Buttons for choices----
abdominalPnB = Button(topframe, text="01_Abdominal Pain")
abdominalPnB.config(anchor="w", width=20, height=1)
abdominalPnB.grid(row=0, column=0)
allergyrxB = Button(topframe, text="02_Allergic Reaction")
allergyrxB.config(anchor="w", width=20, height=1)
allergyrxB.grid(row=1, column=0)
#ect..
root.mainloop()
任何帮助将是惊人的,谢谢!
感谢您的答复!就这样我有一个理解。我会将import emdmenu.py放在导入tkinter下,然后按下我想要按下的按钮,然后调出另一个文件,我只是把command = emdmenu.py,对吧? (目前当我这样做时,它会首先调出emdmenu.py,当我关闭该窗口时,它会弹出一个我想要启动的窗口) – ChrisCrad
不,它应该是'command = function_Name'函数,您的调用应该在函数中形成。导入的任何代码都会在导入时执行,因此请检查您正在导入的文件并确保所有逻辑都位于函数内 – Joe
我强烈建议使用新波士顿。他们有一个网站和YouTube频道。有一整套tkinter系列你可能会觉得有用 – Joe