You can test that the code is working by typing a value within the entry box. Once you run the code in Python, you’ll see the following display with the entry box: This is how the complete code would look like after putting all the above components together: import tkinter as tkĬanvas1 = tk.Canvas(root, width = 400, height = 300)īutton1 = tk.Button(text='Get the Square Root', command=getSquareRoot) The button can be used to execute the getSquareRoot function: button1 = tk.Button(text='Get the Square Root', command=getSquareRoot)Ĭanvas1.create_window(200, 180, window=button1)
So the full getSquareRoot function would look like this: def getSquareRoot (): The square root calculation is captured in the label: The getSquareRoot function will be used to get the value that was typed in the entry box, and then derive the square root. You can specify the position where the entry box would be placed on your Canvas (currently the position is set to 200, 140): entry1 = tk.Entry (root)Ĭanvas1.create_window(200, 140, window=entry1) You can control the dimensions of your Canvas by changing the width and height values: canvas1 = tk.Canvas(root, width = 400, height = 300)Īn entry box can be used to get the user’s input. The Canvas is your display where you can place items, such as entry boxes, buttons, charts and more. Steps to Create an Entry Box using Tkinter Step 1: Create the Canvas Calculate the square root based on the input collectedīy the end of this tutorial, you’ll be able to create the following entry box using tkinter:.An entry box which can be used to get the user’s input.More specifically, you’ll observe a simple example with the steps to create:
In this tutorial, you’ll see how to create an entry box using tkinter.