Intro
In this blog, I am going to create button clicking function in Python GUI application. When user click that Click Me button the button action will perform to change label text and color in that Python GUI application.
Software requirement
Python 3.5 and IDLE (Python 3.5)
Programming code
- import tkinter as tk
- from tkinter
- import ttk
- win = tk.Tk()
- win.title("Python GUI App")
- Lbl = ttk.Label(win, text = "Button Not Click ")
- Lbl.pack()
- def click(): action.configure(text = "Clicked")
- Lbl.configure(foreground = 'red')
- Lbl.configure(text = 'Button Clicked')
- action = ttk.Button(win, text = "Click Me", command = click)
- action.pack()
- win.mainloop()
About the code
First, I am Import the tkinter module, Next assign a class and variables and create application title and label in following code.after label creation next button creation code next button clicking function code and finally I am started the windows event loop by calling the mainloop method then execute the code the python GUI application will appear on screen.
Output
Before Click
After Click