I am working on a chat program and I want the program to change icon when it is recieving data but only if its minimized. And when you pull the program up again it should change the icon back. I tried just changing it in my recieving thread like this:
def returnrecv():
while True:
recieve = s.recv(1024).decode("utf-8")
winsound.PlaySound('beep.wav', winsound.SND_FILENAME + winsound.SND_ASYNC)
recieveBox.config(state=NORMAL)
timeclock = time.strftime('%H:%M')
recieveBox.insert(END, "[" + timeclock + "]", 'black', "Other: ", 'blue', recieve + "\n\n")
recieveBox.config(state=DISABLED)
recieveBox.see("end")
root.iconbitmap("gouico2.ico")
But how would I program it to only do this when the program is minimized?
You can use root.state()
to check the state of the window.
import tkinter as tk
root = tk.Tk()
def change_icon():
print (root.state())
if root.state() == "iconic":
print ("I am hidden")
root.after(1000, change_icon)
root.after(1000,change_icon)
root.mainloop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.