Raen Lusa lat
Raen Lusa lat

Reputation: 1

using tkinter and pystray at the same time

from pystray import MenuItem as item
import pystray
from PIL import Image
import tkinter as tk

window = tk.Tk()
#아이콘 트레이 행동

def quit_window(icon, item):
    icon.visible = False
    icon.stop()
    # window.destroy() 이거 문제임
    # print("destroy success")
    window.quit()
    print("quit success")


def show_window(icon, item):
    window.after(0, window.deiconify)


def withdraw_window():
    window.withdraw()


window.title("Welcome")

win_width = window.winfo_screenwidth()
win_height = window.winfo_screenheight()#window.인네 아니고난
app_width = 200
app_height = 200

center_width = (win_width / 2) - (app_width / 2 )
center_height = (win_height / 2 ) - (app_height / 2)

#문제 없음
print("모니터 사이즈 : ",win_width, win_height)
print("모니터 중심점 : ", int(center_height), int(center_width))
window.resizable(False, False)
window.geometry(f"{app_width}x{app_height}+{int(center_width)}+{int(center_height)}")
#

#문제있음 왜?
window.config(highlightbackground='black')
label = tk.Label(window,bd=0,bg='black')
window.overrideredirect(True)
window.wm_attributes('-transparentcolor','black')
canbas= tk.Canvas(window, width=win_width, height=win_height, bg = 'black')
#

image = Image.open("icon.jpg")

menu = (item('Quit', quit_window), item('Show', show_window))
icon = pystray.Icon("name", image, "title", menu)
icon.run_detached()
window.protocol('WM_DELETE_WINDOW', withdraw_window)
window.mainloop()

I'm tring to make some little app by using python for my homework, I use pystray and tkinter for make it. when i try to quit by using pystray icon it didn't destroy windows, and even quit() or destroy() both are not working is there any way to solv this? Icon.stop() works, window.quit() not works. -_-

Upvotes: 0

Views: 99

Answers (0)

Related Questions