【发布时间】:2017-10-10 19:29:25
【问题描述】:
我有primary.py:
from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter import ttk
import multiprocessing as mp
import other_script
class GUI:
def __init__(self, master):
self.master = master
def file_select():
path = askopenfilename()
if __name__ == '__main__':
queue = mp.Queue()
queue.put(path)
import_ds_proc = mp.Process(target=other_script.dummy, args=(queue,))
import_ds_proc.daemon = True
import_ds_proc.start()
# GUI
root = Tk()
my_gui = GUI(root)
# Display
frame = Frame(width=206, height=236)
frame.pack()
ttk.Button(frame, text="Select", command=file_select).pack(anchor='nw')
# Listener
root.mainloop()
还有other_script.py:
def dummy(parameter):
pass
运行此程序时,选择文件后,会出现第二个 GUI 窗口。为什么?这是不受欢迎的行为,我希望 dummy 运行。
谢谢。
【问题讨论】:
-
使用 root.withdraw() 消除 Tk() 窗口(发送到 GUI)。 askopenfilename() 打开它自己的窗口,这是您看到的第二个窗口effbot.org/tkinterbook/wm.htm 请注意,“dummy”将在 askopenfilename 返回后运行。
标签: python python-3.x tkinter multiprocessing python-multiprocessing