Application in Tkinter – Technoinc

Application in Tkinter – Technoinc

Today we are going to use the first button and text widgets in our application. Where two-button, two labels, and two two text fields are there.

Here is the code for that. First, you can run this code and then try to edit it with your requirements.

Code:-

from tkinter import *

def show_entry_fields():

print(“First Name: %s\nLast Name: %s” % (e1.get(), e2.get()))

e1.delete(0,END)

e2.delete(0,END)

master = Tk()

Label(master, text=”First Name”).grid(row=0)

Label(master, text=”Last Name”).grid(row=1)

e1 = Entry(master)

e2 = Entry(master)

e1.insert(10,”abcd”)

e2.insert(10,”xyzw”)

e1.grid(row=0, column=1)

e2.grid(row=1, column=1)

Button(master, text=’Quit’, command=master.quit).grid(row=3, column=0, sticky=W, pady=4)

Button(master, text=’Show’, command=show_entry_fields).grid(row=3, column=1, sticky=W, pady=4)

mainloop( )

Here we are using two labels i.e First Name and Last Name. Two buttons which are Quit and Show. Where Quit is to terminating our application and by pressing Show button our values of First Name and Last Name is going to print on terminal.

By running our application we can show this type of output.

If we going to press the Show button then it will show the text of text fields on a terminal.

And we get output  like this,

On clicking on the Quit button it will simply close our application.

In the next blog, we are going to use some more buttons in our application, which are radio and check buttons and also we see how to draw different shapes in Tkinter.

Leave a Reply

Your email address will not be published. Required fields are marked *