Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created March 25, 2024 21:56
Show Gist options
  • Save vigilantPotato/6ef7d82c76dc2b0cf53fb19f48940979 to your computer and use it in GitHub Desktop.
Save vigilantPotato/6ef7d82c76dc2b0cf53fb19f48940979 to your computer and use it in GitHub Desktop.
How to on/off sub-window
import ctypes
import tkinter
def show_or_hide_sub_window():
if var.get():
sub_window.deiconify() #show
else:
sub_window.withdraw() #hide
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
root.title("main")
#variable for checkbutton
var = tkinter.BooleanVar(root)
#check button
cb = tkinter.Checkbutton(
root,
text = "sub_window",
variable = var,
command = show_or_hide_sub_window
)
cb.pack()
#sub-window
sub_window = tkinter.Toplevel(root)
sub_window.title("sub")
sub_window.withdraw() #hide sub-window
#label in sub-window
l_s = tkinter.Label(
sub_window,
text = "Label in sub-window",
bg = "lightblue",
)
l_s.pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment