Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 函数使用弹出GUI中的按钮打开主GUI_Python_User Interface_Button_Tkinter - Fatal编程技术网

Python 函数使用弹出GUI中的按钮打开主GUI

Python 函数使用弹出GUI中的按钮打开主GUI,python,user-interface,button,tkinter,Python,User Interface,Button,Tkinter,我是Python新手,试图让启动TFL应用程序按钮打开另一个名为“菜单GUI”的GUI,但我不知道如何处理下面的def open_Menu():函数。我想使用下面的弹出式GUI作为启动器,将用户带到我的主GUI。下面代码的唯一问题是,当您单击启动TFL应用程序的按钮时,该按钮不起任何作用。 以下是我当前的代码: from tkinter import * root = Tk() root.title('TFL App') p = Label(root, text = "TFL

我是Python新手,试图让启动TFL应用程序按钮打开另一个名为“菜单GUI”的GUI,但我不知道如何处理下面的
def open_Menu():
函数。我想使用下面的弹出式GUI作为启动器,将用户带到我的主GUI。下面代码的唯一问题是,当您单击启动TFL应用程序的按钮时,该按钮不起任何作用。 以下是我当前的代码:

from tkinter import *


root = Tk()

root.title('TFL App')

p = Label(root, text = "TFL Journey Planner", height = "18", width = "250", bg = 'brown', fg = 
'white',
      font = ('Helvetica', '20', 'bold', 'italic'))
p.pack()
root.configure(bg = 'brown')
root.geometry('400x700')

photo = PhotoImage(file = 'trainstation.png')
label = Label(root, image = photo)

label.pack()


****#Buttons****

def open_Menu():
    pass
    

Button1 = Button(root, text = "Launch TFL App", command = open_Menu, bg = "black", fg = 'white', padx 
 = 40,
             pady = 10,
             font = ('Calibri Light', '15', 'bold'))
Button1.pack(padx = 25, pady = 0)


Button2 = Button(root, text = "Exit ", command = root.destroy, bg = "black", fg = 'white', padx = 65, 
pady = 8,
             font = ('Calibri Light', '15', 'bold'))
Button2.pack(padx = 25, pady = 10)

root.mainloop()
如何实现
open_menu()

下面的代码是我的主GUI,它应该通过上面的弹出GUI打开,但是弹出GUI上的按钮不工作

from tkinter import *

def find():
# get method returns current text
# as a string from text entry box
    From = From_field.get()
    To = To_field.get()
    travel_modes = mode_field.get()

# Calling result() Function
result(From, To, travel_modes)


# Function for inserting the train string
# in the mode_field text entry box
def train():
    mode_field.insert(10, "train")


# Function for clearing the contents

def del_From():
    From_field.delete(0, END)
    distance_field.delete(0, END)
    duration_field.delete(0, END)


def del_To():
    To_field.delete(0, END)
    distance_field.delete(0, END)
    duration_field.delete(0, END)


def del_modes():
    mode_field.delete(0, END)
    distance_field.delete(0, END)
    duration_field.delete(0, END)



def delete_all():
    From_field.delete(0, END)
    To_field.delete(0, END)
    mode_field.delete(0, END)
    distance_field.delete(0, END)
    duration_field.delete(0, END)


# Driver code
if __name__ == "__main__":
# Create a GUI root
root = Tk()

# Set the background colour of GUI root
root.configure(background = 'light blue')

# Set the configuration of GUI root
root.geometry("600x400")

# Created a welcome to distance time calculator label
headlabel = Label(root, text = 'Welcome to your TFL Journey Planner',
                  fg = 'white', bg = "dark red", height = "0", width = "30",
                  font = ('calibri light', '19', 'italic'))

# Created a From: label
label1 = Label(root, text = "From:",
               fg = 'white', bg = 'black')

# Created a To: label
label2 = Label(root, text = "To:",
               fg = 'white', bg = 'black')

# Created a Distance: label
label4 = Label(root, text = "Distance:",
               fg = 'white', bg = 'black')

# Created a Duration: label
label5 = Label(root, text = "Duration:",
               fg = 'white', bg = 'black')

label6 = Label(root, text = "Choose travelling mode Below: ",
               fg = 'white', bg = 'black')

headlabel.grid(row = 0, column = 1)
label1.grid(row = 1, column = 0, sticky = "E")
label2.grid(row = 2, column = 0, sticky = "E")
label4.grid(row = 7, column = 0, sticky = "E")
label5.grid(row = 8, column = 0, sticky = "E")
label6.grid(row = 3, column = 1)

# Created a text entry box
# for filling or typing the data.
From_field = Entry(root)
To_field = Entry(root)
mode_field = Entry(root)
distance_field = Entry(root)
duration_field = Entry(root)

From_field.grid(row = 1, column = 1, ipadx = "100")
To_field.grid(row = 2, column = 1, ipadx = "100")
mode_field.grid(row = 5, column = 1, ipadx = "50")
distance_field.grid(row = 7, column = 1, ipadx = "100")
duration_field.grid(row = 8, column = 1, ipadx = "100")

# CLEAR Button and attached
# to del_source function
button1 = Button(root, text = "Clear", bg = "light grey",
                 fg = "black", command = del_From)

# Create a CLEAR Button and attached to del_destination
button2 = Button(root, text = "Clear", bg = "light grey",
                 fg = "black", command = del_To)

# Create a RESULT Button and attached to find function
button3 = Button(root, text = "Result",
                 bg = "black", fg = "white",
                 command = find)

# Create a CLEAR ALL Button and attached to delete_all function
button4 = Button(root, text = "Clear All",
                 bg = "light grey", fg = "black",
                 command = delete_all)

# Create a Train Button and attached to train function
button5 = Button(root, text = "Train",
                 bg = "light grey", fg = "black",
                 command = train)

# Create a CLEAR Button and attached to del_modes function
button6 = Button(root, text = "Clear",
                 fg = "black", bg = "light grey",
                 command = del_modes)

button1.grid(row = 1, column = 2)
button2.grid(row = 2, column = 2)
button3.grid(row = 6, column = 1)
button4.grid(row = 9, column = 1)
button5.grid(row = 4, column = 1)
button6.grid(row = 5, column = 2)

root.mainloop()

下面是一个使用子流程导入调用中的
的解决方案。您所要做的就是将“您的文件名”替换为。。。您的文件名:D

from tkinter import *
from subprocess import call

root=Tk()
root.geometry('200x100')
frame = Frame(root)
frame.pack(pady=20,padx=20)

def open_Menu():
    call(["python", "YOUR-FILE-NAME.py"])

btn=Button(frame,text='Open File',command=Open)
btn.pack()

root.mainloop()

它将是什么样子:


我希望这对你有用:D

菜单Gui在哪里,或者你正在寻找菜单Widget菜单是我的主Gui,如果你愿意,我可以发布代码。我想使用上面的弹出Gui作为启动器,将用户带到我的主Gui。上面代码的唯一问题是,当您单击“启动TFL应用程序”按钮时,该按钮不起任何作用。请这样做,但请解释您的问题。我的猜测是,您想从另一个GUI窗口中的按钮打开一个GUI窗口吗?然后看看顶级小部件,它可能会很有帮助,很乐意提供帮助!祝你的项目好运:D