# Encoding = utf-8import tkinter as TK # create a window = TK. TK () # Set the window title window. title ("My first tkinter window") # Set the window size window. geometry ("300x200") # defines string variables. You can set and obtain the value Var = TK of string variables. stringvar () color_flag = false # define the action when you click the button, alternately explicit \ non-explicit label text def get_label_color (): Global color_flag if color_flag = false: color_flag = true var. set ("I Have Been clicked") else: color_flag = false var. set ("") # define a label. bg is the background color label_1 = TK. label (window, textvar = var, BG = "green", width = 20, Height = 2, font = 20) # Place the label on the window label_1.pack () # define a button = TK. button (window, text = "Click me", width = 15, Height = 2, command = get_label_color) # Place the button on the window button. pack () # loop detection window. mainloop ()
Tkinter _ a simple window