Lesson 11

this is python lesson 11

This is lesson we shall add more to the GUI we created last lesson. We shall add a label, an entry box and a button. Let’s start!

import tkinter


window.title(“Graphical User Interface”)


lbl = tkinter.Label(window, text = “PythonStar”)


ent = tkinter.Entry(window)


btn = tkinter.Button(window, text=”Click Here”)



This may look complicated but it is very simple. We make an entry box, button or label, choose the text and then pack it into our GUI. At the moment our button doesn’t do anything. But we can change that.

def button_clicked():

            print(“Button Clicked”)

btn = tkinter.Button(window, text= “Click Here”, command=buttonclicked)

The above code makes the button interactive. You can put anything in the function and make the button do anything. But to use the function we just add command=button_clicked into the code for the button. Simple. Now we are going to add a way to get the text from an entry box and then you could you use it to make a login.

def entry_input():


btn = tkinter.Button(window, text=”Get Input”, command = entry_input)


The above piece of code makes the program print the text in the entry box when the button is clicked. You don’t have to print it you can do anything with it. Next lesson, now we have working interactive GUIs we will make then look nice. See what you can make: a calculator or a login? The possibilities are endless.