I have built an app with PySide2 (PyQt). Now I was asked to make a QPushButton, which simply starts an independent Tkinter app which someone else has programmed. I thought I could simply connect the method below to my QPushButton which starts the Tkinter App (Modell_final.App is the app):
def open_tkinter():
root = tkinter.Tk()
app = Modell_final.App(root)
root.mainloop()
But when I push the Button inside my GUI the first time nothing happens and the second time the Tkinter App opens and freezes immediately. Thanks for help:)
I am not sure how independent the Tkinter app is. If it is truly just some other small window you want to run that eventually gets closed again I would opt for an own process for it.
You can try it like this. Please save it as "test_test.py"
import tkinter as tk
import subprocess
window = tk.Tk()
window.title("Window Title")
window.geometry('200x100')
lbl = tk.Label(window, text="Hello World")
lbl.pack()
def clicked(): #function before bind
subprocess.Popen(['python' , 'test_test.py'])
btn = tk.Button(window, text="Click Me", command=clicked)
btn.pack()
window.mainloop()
If it is truly completly independet this would have the benefit that you do not even need to import the Modell_final into the PyQt app. Just import subprocess and let the button call the subprocesss.popen
(not subprocesss.call
, then it freezes again) python file with the tkinter app in it.
The downside is
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.