Rewrite this program to hide it in system tray when window minimize button clicked. Tray…
- User
Rewrite this program to hide it in system tray when window minimize button clicked. Tray icon menu when right clicked: show, action1, action2, close. Default action on left click is "show". Program not hidden by default
import tkinter as tk from tkinter import messagebox
def button1_clicked(): messagebox.showinfo(“Button 1”, “Button 1 was clicked!”)
def button2_clicked(): messagebox.showinfo(“Button 2”, “Button 2 was clicked!”)
def button3_clicked(): value = entry_field.get() is_checked = checkbox_var.get() messagebox.showinfo(“Button 3”, f"Entry Value: {value}\nCheckbox is {‘checked’ if is_checked else ‘not checked’}")
Create the main window
window = tk.Tk() window.title(“Fixed Size Window App”) window.geometry(“300x200”) # Fixed window size 300x200 pixels
Create a frame for the input field and Button 1
input_frame = tk.Frame(window) input_frame.pack(pady=10)
Create labels
label1 = tk.Label(window, text=“Label 1”) label1.pack()
label2 = tk.Label(window, text=“Label 2”) label2.pack()
Create an entry field
entry_field = tk.Entry(input_frame) entry_field.grid(row=0, column=0, padx=5)
Create Button 1 and place it in line with the input field
button1 = tk.Button(input_frame, text=“Button 1”, command=button1_clicked) button1.grid(row=0, column=1)
Create a checkbox
checkbox_var = tk.BooleanVar() checkbox = tk.Checkbutton(window, text=“Check me”, variable=checkbox_var) checkbox.pack()
Create Button 2 and Button 3
button2 = tk.Button(window, text=“Button 2”, command=button2_clicked) button2.pack(pady=5)
button3 = tk.Button(window, text=“Button 3”, command=button3_clicked) button3.pack(pady=5)
Disable resizing the window
window.resizable(False, False)
Start the GUI loop
window.mainloop()
- Assistant