我有一个程序,当找不到.txt文件时,当前运行四个窗口,当它是时,只有一个。在没有文本文件的情况下运行代码时,第一个窗口的图标就可以了。对于其他三个,它很模糊。存在文件时,图标不会模糊。打开第二个窗口似乎很模糊。我想知道是否有人可以提供帮助?
import os
import ctypes
from tkinter import *
configfile = "config.txt"
newname = ""
def accept():
global errorbox
errorbox.destroy()
def errorrun(title, message, w, h):
global errorbox
errorbox = Tk()
errorbox.title(title)
errorbox.iconbitmap(default = "favicon.ico")
errorlabel = Label(errorbox, text = message).pack()
errorbutton = Button(errorbox, text = " Ok ", command = accept).pack()
ws = errorbox.winfo_screenwidth()
hs = errorbox.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
errorbox.geometry('%dx%d+%d+%d' % (w, h, x, y))
errorbox.mainloop()
def entryapp():
global newname
global entrywindow
global entering
newname = entering.get()
entrywindow.destroy()
def entrybox(title, message, w, h):
global entrywindow
global entering
entrywindow = Tk()
entrywindow.title(title)
entrywindow.iconbitmap(default = "favicon.ico")
entrylabel = Label(entrywindow, text = message).pack()
entering = Entry(entrywindow)
entering.pack()
entrylabelgap = Label(entrywindow, text = " ").pack()
entrybutton = Button(entrywindow, text = " Ok ", command = entryapp).pack()
ws = entrywindow.winfo_screenwidth()
hs = entrywindow.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
entrywindow.geometry('%dx%d+%d+%d' % (w, h, x, y))
entrywindow.mainloop()
if os.path.exists(configfile):
pass
else:
errorrun("Cannot find file!", "\nThe configuration file was not found.\nCreating one now.\n", 320, 100)
config = open(configfile,"w")
config.close()
config = open(configfile,"r")
name = config.readline(1)
if name == "":
config.close()
config = open(configfile,"w")
errorrun("No name detected!", "\nNo name has been detected.\n", 320, 90)
entrybox("Name entry!", "\nPlease enter your name:\n", 320, 130)
config.write(newname)
config.close()
def mainmenu():
mainwindow = Tk()
mainwindow.iconbitmap(default = "favicon.ico")
mainwindow.wm_title("Student management system!")
w = 500
h = 500
ws = mainwindow.winfo_screenwidth()
hs = mainwindow.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
mainwindow.geometry('%dx%d+%d+%d' % (w, h, x, y))
mainwindow.mainloop()
mainmenu()