打开.py文件时Tkinter Gui未运行

2024-04-26 00:38:13 发布

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

我正在做这个项目,我想添加一个GUI界面。我选择使用Tkinter,因为我对Python有点熟悉。我遇到了一个问题,我可以在VisualStudio之外运行GUI,但我无法直接在桌面上运行GUI。我已经检查过了,代码中没有错误。谁能帮我修一下密码吗

这是我用来运行GUI的代码片段

from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import ttk
from tkinter import messagebox

import os
import shutil
from os import listdir
from os.path import isfile, join
import getpass
import time

window = Tk()
window.title("Move Files")
window.geometry('546x500')

def Movie():
    TextBox.delete('1.0',END)
    bar['value'] = 0
    messagebox.showinfo('Message title', 'Message content')

def TVShow():
    TextBox.delete('1.0',END)
    bar['value'] = 0
    TVShowMove()

#Buttons
Movie = Button(window,text='Move Movies', command=Movie, padx=50, pady=30)
Movie.place(x=40, y=40)
TVShow = Button(window,text='Move TV Shows', command=TVShow, padx=48, pady=30)
TVShow.place(x=300, y=40)

#Progressbar
bar = Progressbar(window, length=446, style='black.Horizontal.TProgressbar')
bar.place(x=40, y=140)

#TextBox
TextBox = Text(window, height=10, width=55)
TextBox.pack()
TextBox.place(x=40, y=170)
window.mainloop()

Tags: 代码fromimportmoveostkinterbarplace
2条回答

在Python3.8中,您不能导入其中任何一个

from tkinter.ttk import Progressbar
from tkinter import ttk
from tkinter import messagebox

相反,您必须将Tkinter作为tk导入,如下所示

from tkinter import *
import tkinter as tk

代码没问题 我也有这个问题! 尝试从vscode本身打开它

相关问题 更多 >