python3.8 在tkinter中写了quit不退出,怎么办?

python3.8 在tkinter中写了quit不退出,怎么办?

在tkinter中写了quit不退出,怎么办?

详见代码第102行,wait函数下

由于想给自己孩子写个能定时锁屏的软件,就制作起来,结果遇到了不退出的bug,还请各位大佬看一下,指出错误,在此提前致谢

注:注释掉的部分是以后的功能

相关代码

# -*- coding:utf-8 -*-

import ctypes

import os

import threading

import time

import tkinter as tk

from subprocess import run

from plyer import notification

from PIL import Image, ImageTk

from win10toast import ToastNotifier

#whnd = ctypes.windll.kernel32.GetConsoleWindow()

# if whnd != 0:

# ctypes.windll.user32.ShowWindow(whnd, 0)

# ctypes.windll.kernel32.CloseHandle(whnd)

class Application(tk.Tk):

def __init__(self):

super().__init__()

self.bit_Lock = True

self.bit_inform = True

self.bit_pop_up = True

self.Locking_time = 10

self.wm_attributes('-topmost', True)

self.toaster = ToastNotifier()

# self.protocol("WM_DELETE_WINDOW",self.no_closing)

if os.path.exists('D:/GQC/ALdata'):

with open('D:/GQC/ALdata', 'r') as f:

self.Lock_time = int(f.readlines()[0].replace("\n", ""))

else:

with open('D:/GQC/ALdata', 'a+') as f:

f.write("60")

self.Lock_time = 60

self.Lock_time = 10

#self.l = tk.StringVar()

#self.lbl_Lock_time = tk.Label(self,textvariable=self.l,font=(None,50))

# self.overrideredirect(True)

while self.bit_Lock:

# self.l.set(str(self.Lock_time)+"秒后锁屏")

# self.lbl_Lock_time.pack(fill=tk.X)

# self.update()

if self.Lock_time == 0:

self.overrideredirect(False)

self.Lock()

self.Lock_time = 10

if self.bit_inform:

if self.Lock_time == 300:self.Notify_time("五分钟")

if self.Lock_time == 120:self.Notify_time("两分钟")

if self.Lock_time == 60:self.Notify_time("一分钟")

if self.Lock_time == 30:self.Notify_time("30秒")

if self.Lock_time == 10:self.Notify_time("10秒")

self.Lock_time -= 1

print("锁屏倒计时", self.Lock_time)

time.sleep(1)

def Notify_time(self,time):

notification.notify(

title="自动锁屏通知",

message=f"您当前使用的电脑即将锁屏,剩余时间小于"+time+",请尽快保存未保存的工作,避免数据丢失",

app_icon=os.path.join(os.path.abspath('.'),'images','ring.ico'),

timeout=10)

def Lock_windows(self):

self.frame = tk.Frame(self, bg="LightGrey")

# self.attributes('-fullscreen',True)

self.v = tk.StringVar()

#img_open = Image.open(os.path.join(os.path.abspath('.'),'images','wallpaper.jpg'))

# img=ImageTk.PhotoImage(img_open)

self.lbl_time = tk.Label(self, textvariable=self.v, font=(

"微软雅黑", 100), anchor=tk.N, fg='DeepSkyBlue') # DodgerBlue ,image=img,compound=tk.CENTER

self.lbl_time.pack(fill=tk.X)

self.frame.pack(fill="both", expand=True)

while self.Lock_bool:

self.v.set(str(self.x)+"秒后解除锁屏")

self.lbl_time.pack()

self.update()

# self.attributes('-fullscreen',False)

self.v.set("解除锁屏")

self.lbl_time.pack()

self.update()

def no_closing(self):

pass

def close_explorer(self):

run('taskkill /F /IM explorer.exe')

def wait(self):

for self.x in range(self.Locking_time, 0, -1):

time.sleep(1)

print("恢复倒计时", self.x)

self.Lock_bool = False

time.sleep(1)

self.quit()

os.system('start explorer.exe')

print("已恢复")

time.sleep(5)

def Lock(self):

self.Lock_bool = True

t1 = threading.Thread(target=self.wait)

t1.start()

self.close_explorer()

self.Lock_windows()

t1.join()

app = Application()

app.mainloop()

我想让它等待10秒后退出,结果却无法退出窗体,能帮我看一下错在哪里了吗?,再次致谢

以上是 python3.8 在tkinter中写了quit不退出,怎么办? 的全部内容, 来源链接: utcz.com/p/938061.html

回到顶部