DEV Community

dhakshinesh
dhakshinesh

Posted on • Edited on

4 2

Tkinter, Creating Forms

NOTE

If you are coming here for the first time or have no idea about tkinter, checkout the Getting Started dev-post

In this tutorial we will be creating a simple signup form which contains some text field, Checkbox, and a submit button.

Entry Widget

The entry widget is used for creating input fields.
Syntax :

#text field : username
Label(root, text="Username").grid(row = 0,column = 0)
Entry(root).grid(row = 0,column = 1)
#text field : password
Label(root, text="Password").grid(row = 1,column = 0)
Entry(root).grid(row = 1,column = 1)
Enter fullscreen mode Exit fullscreen mode

Here, I'm using grid placement which allows us to place all items in a tabular manner.

CheckButton Widget

Using this widget, we can create a simple checkbox which we can toggle on or off.

Syntax:

#Checkbox field
Checkbutton(root,text="Remember?").grid(row=2, column=1)
Enter fullscreen mode Exit fullscreen mode

The text variable basically replaces the Label widget's role and also acts as a checkbox whenever you click on the text which makes your application more accessible.

Button Widget

As you already know, the Button widget is basically a button ;)

#Submit button
Button(root, text = 'Submit').grid(row=3, column=0)
Enter fullscreen mode Exit fullscreen mode

That's it. You can make it more beautiful by making the form centered and then adding some colors to it too.

I've made a GitHub repository too. (feel free to make some PR's) :
Tkinter-Creating-Forms

Neon image

Serverless Postgres in 300ms (!)

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches. No credit card needed.

Try for Free →

Top comments (0)

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

👋 Kindness is contagious

DEV works best when you're signed in—unlocking a more customized experience with features like dark mode and personalized reading settings!

Okay