简体   繁体   English

TypeError : int() 参数必须是字符串、类似字节的对象或数字,而不是 Python Tkinter 中的“条目”

[英]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.

相关问题 错误测试python代码:TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“ NoneType” - Error testing python code: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' TypeError: int() 参数必须是字符串、类似字节的对象或数字,而不是 python3 中的“NoneType”错误 - TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' error in python3 Python 2-TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是“列表” - Python 2 - TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' Python:TypeError:int() 参数必须是字符串、类似字节的对象或数字,而不是“NoneType” - Python: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' 类型错误:将形状转换为 TensorShape 时出错:int() 参数必须是字符串、类似字节的对象或数字,而不是“元组”。 在蟒蛇 - TypeError: Error converting shape to a TensorShape: int() argument must be a string, a bytes-like object or a number, not 'tuple'. in python TypeError: int() 参数必须是字符串、类似字节的对象或数字,而不是“NoneType”(HTML 将输入发送到 Python) - TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' (HTML send input to Python) TypeError: int() 参数必须是一个字符串,一个类似字节的 object 或一个数字,而不是使用 Python 3.7 时的“NoneType” - TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' while using Python 3.7 TypeError: int() 参数必须是一个字符串,一个类似字节的 object 或一个数字,而不是“NoneType”。 但我写了 int() - TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'. But I wrote the int() int()参数必须是字符串,类似字节的对象或数字,而不是“元组” - int() argument must be a string, a bytes-like object or a number, not 'tuple' int() 参数必须是字符串、类似字节的对象或数字,而不是 &#39;QueryDict&#39; - int() argument must be a string, a bytes-like object or a number, not 'QueryDict'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM