Introduction
In this blog, I am going to create a textbox and text capturing function in Python GUI application. When a user enters the text in the textbox and clicks the Submit button, the button action will capture the text and display the Hi text in Python console.
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 = "Enter the name:").grid(column = 0, row = 0)
- def click():
- print("Hi," + name.get())
- name = tk.StringVar()
- nameEntered = ttk.Entry(win, width = 12, textvariable = name).grid(column = 0, row = 1)
- button = ttk.Button(win, text = "submit", command = click).grid(column = 1, row = 1)
- win.mainloop()
About the code
- First, I am importing the tkinter module.
- Next, I assign a class and label variables and give the application title.
- After label creation, next, I define click function then create textbox and button in the code.
- Finally, I have started the Windows event loop by calling the main loop method and executed the code.
The Python GUI application will appear on the screen.
Output