Created
March 25, 2024 21:56
-
-
Save vigilantPotato/6ef7d82c76dc2b0cf53fb19f48940979 to your computer and use it in GitHub Desktop.
How to on/off sub-window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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