Using Buttons in Python - 2 - The Advantages of Learning Python Programming for Beginners: A Comprehensive Guide

Latest

Dive into the world of Python programming with our comprehensive resources

Music

logo

Friday, December 16, 2022

Using Buttons in Python - 2

 

In this article, we define the event function for the command property of the button object. When the button is clicked, the code in the function is executed.  When we click the button, we will print the text entered in the entry object to the console screen.

 


 

 

 

 

 

 

 

Figure 1

 

root = tk.Tk()

root.title("Hi!..bs")

root.geometry("350x80")

lbl = ttk.Label(root, text = "Enter the name:").grid(column = 0, row = 0,padx=30,pady=2)

   

def event():  

   print("Hi," + name.get())

name = tk.StringVar() 

tbox = ttk.Entry(root, width = 20, textvariable = name).grid(column = 0, row = 1,padx=15,pady=3)

button = ttk.Button(root,width = 20, text = "Click", command = event).grid(column = 1, row = 1,padx=20,pady=3) 

root.mainloop()  

 

We have come to the end of this article. See you in our next article. Happy coding. Bahadir Sahin

 

We have come to the end of this article. See you in our next article. Happy coding. Bahadir Sahin

No comments:

Post a Comment

Featured post

Python Introduction

What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built ...