[英]TypeError : int() argument must be a string, a bytes-like object or a number, not 'Entry' in Python Tkinter
As I started creating a GUI calculator in Python using Tkinter in Python 3.8当我开始在 Python 3.8 中使用 Tkinter 在 Python 中创建 GUI 计算器时
I got stuck at a situation where i want to get the entry by the user in diffent entry box and the user is given four option wether to add , substract , multiply or divide我遇到了一种情况,我想让用户在不同的输入框中输入,而用户有四个选项可以加减乘除
but as i was doing it was showing an error like this但是当我这样做时,它显示了这样的错误
int() argument must be a string, a bytes-like object or a number, not 'Entry'
I seriously dont know what is this type of error as i am a beginer in python and it is my first GUI project我真的不知道这种类型的错误是什么,因为我是 python 的初学者,这是我的第一个 GUI 项目
the Entire Code is as follows:完整代码如下:
from tkinter import *
from tkinter import messagebox
import self as self
global root
top = Tk()
top.title("Alex Mercer")
def default():
messagebox.showinfo("Guilty Message",
"Sorry! But this feature is not Yet Available Please Come Back after the available of the future update of this program\n Our E-mail Adress Is: alexmercerr07@gmail.com")
def create_window():
window = Toplevel(top)
window.title("Message")
default()
def helpyou():
window = Toplevel(top)
window.title("Help")
ourmessage = "Please Email Your Problem To our E-mail Adress : alexmercerr07@gmail.com"
default()
w = 500
h = 500
menu = Menu(top)
top.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label="New", command=create_window)
filemenu.add_command(label="Help", command=helpyou)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=quit)
editmenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editmenu)
editmenu.add_command(label="Cut", accelerator="Ctrl+V", command=lambda:
self.editor.event_generate('<Control-x>'))
editmenu.add_command(label = "Copy",accelerator="Ctrl+V", command=lambda:
self.noteBook.event_generate('<Control-c>'))
editmenu.add_command(label = "Paste", accelerator="Ctrl+V", command=lambda:
self.noteBook.event_generate('<Control-v>'))
Label(top, text = "Enter The First Number : ").grid(row = 0, padx = 10, pady = 20)
Label(top, text = " Enter The Second Number : ").grid(row = 1, padx = 22, pady = 30)
firstvar = Entry(top)
secondvar = Entry(top)
firstvar.grid(row = 0, column = 1)
secondvar.grid(row = 1, column = 1)
top.geometry("{}x{}".format(w,h))
def add():
you = int(firstvar)
you2 = int(secondvar)
result = you + you2
return result
var = int(add())
b = Button(top, text = "ADD", command = add)
Label(top, text = "Your Result is : {}".format(var))
mainloop()
You should first call .get()
to your entry then convert it to integer.您应该首先调用
.get()
到您的条目,然后将其转换为整数。 Simply do, you = int(firstvar.get())
see if it works.简单地做,
you = int(firstvar.get())
看看它是否有效。 (I just found this info with quick google search, here is the source https://riptutorial.com/tkinter/example/30023/getting-int-from-entry-widget ) (我刚刚通过快速谷歌搜索找到了这个信息,这是来源https://riptutorial.com/tkinter/example/30023/getting-int-from-entry-widget )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.