大佬教程收集整理的这篇文章主要介绍了Tkinter程序运行功能,但结束后弹出窗口,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
好的,所以我对 tkinter 还很陌生,我无法解决我遇到的这个问题。
当我运行程序时,它运行该函数,并在它结束后弹出带有照片的窗口,但循环不会再次启动程序。
import tkinter as tk
from tkinter import*
from PIL import ImageTk,Image
from tkinter import messageBox
import YuaChanMainFunc
import time
def on_click(event=NonE):
# `command=` calls function without argument
# `bind` calls function with one argument
print("hey Yua!")
YuaChanMainFunc.statement="hey yua"
class Window(FramE):
def __init__(self,master=NonE):
super().__init__(master)
self.master = master
self.pack()
master.title("Yua-chan AI")
self.img = ImageTk.PhotoImage(Image.open("YuaChanAI/Yua Chan Artwork/YuaChan2.png"))
MainLB = tk.Label(master,image=self.img)
MainLB.bind('<button-1>',on_click)
MainLB.pack()
b = tk.button(root,text="Close",command=root.destroy)
b.pack()
#YuaChanMainFunc.YuaChanaimainFunc()
root = tk.Tk()
#instance of the class
app = Window(root)
root.resizable(0,0)
root.geometry("310x500+1600+510")
YuaChanMainFunc.YuaChanaimainFunc()
#Runs the application until we close
root.mainloop()
据我所知你想要“YuaChanMainFunc.YuaChanAIMainFunc()” 在 UI 运行前台时在后台运行。为此,您可以在不同的线程中启动“YuaChanMainFunc.YuaChanAIMainFunc()”并在主线程本身中运行 UI。现在你可以让 "YuaChanMainFunc.YuaChanAIMainFunc()" 成为一个无限循环,它不会阻塞 root.mainloop()。还要记住 root.mainloop() 也是一个无限循环。因此,在关闭程序之前,您之后编写的任何内容都不会执行。
import threading
BACkend_thread = threading.Thread(target=YuaChanMainFunc.YuaChanAIMainFunc,args=())
BACkend_thread.daemon = True #This will make sure BACkend thread closes when you close ui
BACkend_thread.start()
root.mainloop()
以上是大佬教程为你收集整理的Tkinter程序运行功能,但结束后弹出窗口全部内容,希望文章能够帮你解决Tkinter程序运行功能,但结束后弹出窗口所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。