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