【发布时间】:2020-03-12 16:38:56
【问题描述】:
所以.. 当我尝试运行我的 Tkinter 脚本时,它会立即打开和关闭一个命令提示符窗口,但是当我从本机 Python IDLE 启动它时,该脚本运行得非常好......
我尝试将 .py 更改为 .pyw,以便从命令行启动它..
这是我的代码:
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()
请帮帮我????
【问题讨论】:
-
这非常适合我。只需在命令行中写
python myfile.py -
没用.. 如您所见:ibb.co/Vq1Tjf1
-
我认为脚本
mainpage.py实际上不包含最后一行window.mainloop()。所以它在 IDLE 中可以正常工作,但在控制台中却不行。
标签: python python-3.x tkinter command-line