两个不同GUI窗口的问题

2024-09-29 00:16:40 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我的第一个GUI窗口用于从用户处获取输入:

from tkinter import *
from main import *


root = Tk()

root.configure(background="orange")
root.wm_title("Python Project")

label_1 = Label(root, text="Project Name",bg="orange",fg="black")
label_2 = Label(root, text="Site URL Link",bg="orange",fg="black")
entry_1 = Entry(root)
entry_2 = Entry(root)

label_1.grid(row=0,sticky=W)
label_2.grid(row=3333,sticky=W)

entry_1.grid(row=0,column=1,padx=50,ipadx=100)
entry_2.grid(row=3333,column=1,ipadx=100)

def callback():
    a1 = entry_1.get()
    a2 = entry_2.get()
    mmm(a1,a2,root) # main program


button1 = Button(root,text="Run",command=callback)
button2=Button(root,text="Quit",command=root.quit)

button1.grid(row=3334,ipadx=15,padx=50,column=1)
button2.grid(row=3335,column=1,ipadx=15,padx=50)


root.mainloop()

然后我用这个论坛的另一个GUI窗口来显示我的结果:

from tkinter import *


root = Tk()
textbox = Text(root)
textbox.pack()

def redirector(inputStr):
    textbox.insert(INSERT, inputStr)

sys.stdout.write = redirector  # whenever sys.stdout.write is called, redirector is called.
sys.stderr.write = redirector

root.mainloop()

现在每次我运行第一个GUI时,两个GUI都会打开,尽管代码还不可能到达第二个GUI代码。。。这里有什么问题?你知道吗

另外,第二个GUI应该从一个类打印出来,但是当我试图把它放在那里时,我有一大堆错误。为了使第二个GUI与类一起工作,我需要做哪些更改?你知道吗


Tags: textfromimportguicolumnrootlabelgrid