Windows 11下Tkinter GUI窗口空白仅Visual Studio中可正常运行的问题求助
Windows 11下Tkinter GUI窗口空白仅Visual Studio中可正常运行的问题求助
我有一个基于Python 3.7的项目,在Windows 10上运行完全正常,但自从强制更新到Windows 11后,GUI就出问题了:Tkinter窗口能显示,但里面是空的,按钮、页面都看不到。奇怪的是,在Visual Studio里运行却完全正常,而且全程没有任何错误提示。
以下是我认为相关的代码片段,原本应该打开带按钮的多页面界面:
#! /usr/bin/python3 import sys import os from tkinter import * from tkinter.ttk import * from tkinter import simpledialog style = Style() style.configure('W.TButton', font =('calibri', 45, 'bold'), foreground = 'black',background='orange') style.configure('Z.TButton', font =('calibri', 30, 'bold'), foreground = 'black',background='orange') style.configure('S.TButton', font =('calibri', 45, 'bold'), foreground = 'white',background='red') style.theme_settings("default",{"TNotebook.Tab": {"configure":{"padding": [30, 30]}}}) style.configure('Tnotebook.Tab', font =('calibri', 50, 'bold')) root.geometry("1200x600+40+100") root.title("Program name here") nbook = Notebook(root) page1 = Frame(nbook, style='') nbook.pack(fill=BOTH, expand=1) # handles closing root.protocol("WM_DELETE_WINDOW", on_closing) root.mainloop()
正常情况下的界面应该是这样的:
我试过参考其他帖子的方法,把root.mainloop()移到不同位置,但都没用。因为之前在Win10正常、VS里也正常,我实在不知道还有什么可以尝试的方向了。
更新:我后来升级到了Python 3.13,问题依然存在。现在我把问题范围缩小到了一段检查文件的代码——这段代码用来判断要显示哪些标签页:
if os.path.exists('playback'): print("playback Exists") nbook.add(page1, text="Page One Title")
这里os.path的返回有问题,我用print(os.path)得到的结果是<module 'ntpath' (frozen)>。
备注:内容来源于stack exchange,提问作者Bolted_Fault
相关产品推荐
相关产品推荐

