- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change Entry.get() into an integer in Tkinter?
The Entry widget in Tkinter is generally used to accept one-line input in the text field. We can get the output from the Entry widget using .get() method. However, the .get() method returns the output in string format. For example, if the user types an integer number in the Entry widget, it gets converted to a string. To change the type of the Entry input into an integer, we can cast the string to an integer.
Example
In this example, we have shown how to calculate the sum while taking an integer input from the user.
# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") def cal_sum(): t1=int(a.get()) t2=int(b.get()) sum=t1+t2 label.config(text=sum) # Create an Entry widget Label(win, text="Enter First Number", font=('Calibri 10')).pack() a=Entry(win, width=35) a.pack() Label(win, text="Enter Second Number", font=('Calibri 10')).pack() b=Entry(win, width=35) b.pack() label=Label(win, text="Total Sum : ", font=('Calibri 15')) label.pack(pady=20) Button(win, text="Calculate Sum", command=cal_sum).pack() win.mainloop()
Output
- Related Articles
- How to place an image into a frame in Tkinter?
- How to convert an integer into a date object in Python?
- How to Change Tkinter Frame Title?
- How to convert a string vector into an integer vector in R?
- How to change the title bar in Tkinter?
- How to change text cursor color in Tkinter?
- Java Program to convert an integer into binary
- How do I convert a string into an integer in JavaScript?
- How to change the font on ttk.Entry in Tkinter?
- How to change the mouse pointer color in Tkinter?
- How to insert an 8-byte integer into MongoDB through JavaScript shell?
- How to convert a string into an integer without using parseInt() function in JavaScript?
- Golang Program to convert an integer into binary representation
- Haskell Program to convert the string into an integer
- C++ Program to convert the string into an integer

Advertisements