[英]Double click on .py tkinter file doesn't work
So.. When I'm trying to run my Tkinter script, that opens and closes immediatly a command prompt window, but the script run perfectly good when I launch it from the native Python IDLE...所以..当我尝试运行我的 Tkinter 脚本时,它会立即打开和关闭一个命令提示符窗口,但是当我从本机 Python IDLE 启动它时,脚本运行得非常好......
I have tried to change .py to .pyw, to launch it from command line..我试图将 .py 更改为 .pyw,以从命令行启动它。
Here is my code:这是我的代码:
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
from subprocess import call
import webbrowser
import sys
import os
window = Tk()
window.title("xx's App")
window.geometry("600x400+100+100")
window['bg'] = "white"
#We define all the function here
def webSite_yofr():
webbrowser.open_new("http://x")
def webSite_cf():
webbrowser.open_new("http://xx")
def webSite_ga():
webbrowser.open_new("https://xxx")
def webSite_dream():
webbrowser.open_new("https://xxxx.fr")
def appLeaving():
print("Leaving..")
window.destroy()
def loginScript():
print("App has started")
call(["python", "LoginPage"])
topbarMenu = Menu(window)
optionsMenu = Menu(topbarMenu, tearoff=0)
topbarMenu.add_cascade(label="Options", menu=optionsMenu)
optionsMenu.add_command(label="Leave app", command=appLeaving)
#Sous menu site web
siteMenu = Menu(topbarMenu, tearoff=0)
topbarMenu.add_cascade(label="Site web", menu=siteMenu)
siteMenu.add_command(label="x", command=webSite_yofr)
siteMenu.add_command(label="xx", command=webSite_ga)
siteMenu.add_command(label="xxx", command=webSite_cf)
siteMenu.add_command(label="Le domaine de mes réves..", command=webSite_dream)
#Titre application
text1 = Label(window, text="L'application de la xx's xx", background="white")
text1.configure(font=("Comic Sans Ms", 15, "bold"))
text1.pack()
#saut de ligne
textSL = Label(window, text=" ", background="white")
textSL.pack()
#Bouton se connecter
button1 = Button(window, text="Commencer !", command=loginScript)
button1.configure(font=("Comic Sans Ms", 12, "normal"))
button1.pack()
window.config(menu=topbarMenu)
window.mainloop()
Please help me 😓请帮帮我😓
感谢@acw1668,我实际上忘记将window.mainloop()
放在我的代码末尾啊哈
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.