...

/

Adding a Button to the GUI App

Adding a Button to the GUI App

In this lesson, we will add a button widget to our GUI app.

Adding a button

We can use the following syntax to create a button:

Press + to interact
button_name = tk.Button(window, text = "some text")
button_name.grid(column=1,row=0)

We use window as the first argument of the Button method to connect the button to our window.

Let’s add the button we created in the ...

import tkinter as tk

window = tk.Tk()
window.title("My Window")
window.geometry("1000x600")

mylabel = tk.Label(text = "Hello World!")
mylabel.grid(column=0,row=0)

mybutton = tk.Button(window, text = "Click Me")
mybutton.grid(column=0,row=1)

window.mainloop()
Adding a button to the GUI

Click the “Run” button to run the code and ...