简体   繁体   English

TypeError:“ str”和“ int”的实例之间不支持“>”

[英]TypeError: '>' not supported between instances of 'str' and 'int'

this error keeps popping up left, right, and center in my code. 此错误不断在我的代码中向左,向右和居中弹出。 it's really annoying. 真烦人。 till now, I've fixed them all but i can't seem to be able to fix this one. 到现在为止,我已经解决了所有问题,但似乎无法修复。

Traceback (most recent call last):
File "C:\Users\Home\Desktop\da.py", line 31, in <module>
if (number > 1):
TypeError: '>' not supported between instances of 'str' and 'int'

the code itself: 代码本身:

    from tkinter import *
from tkinter import ttk
import tkinter as tk
def add_text():
    global number
    number = num_textbox.get()
    print(number)
root = Tk()
root.title("Number Cent Divider")
root.geometry("330x85")
num_col_mat = Label(root, text="Your number:")
num_col_mat.pack()
num_textbox = Entry(root, bd=1)
num_textbox.pack()
enter_button = Button(root, text="Enter", command=add_text)
enter_button.pack()
root.mainloop()
if (number[-1] == 5 or number[-1] == 0):
    number / 5
    int(number)
    if (number > 1):
        answer = "\number 5 cent coins"
        str(number)
        popup()
    else:
        answer = "\number 5 cent coin"
        str(number)
        popup()
else:
    int(number)
    if (number > 1):
        answer = "\number 1 cent coins"
        str(number)
        popup()
    else:
        answer = "\number 1 cent coin"
        str(number)
        popup()
def popup():
    popup = tk.Tk()
    popup.wm_title("answer")
    answer = Label(popup, text=answer)
    answer.pack
    B1 = ttk.Button(popup, text="Ok", command=popup.destroy)
    B1.pack()

any help would be appreciated since this error does not want to get fixed. 任何帮助将不胜感激,因为此错误不想得到解决。

number is a str , so you first need to convert it to a number. number是一个str ,因此您首先需要将其转换为数字。 Eg: 例如:

if int(number) > 1

Writing int(number) on a line by itself doesn't do anything... it just returns a number, which is then ignored. 单独在一行上写int(number)不会做任何事情……它只会返回一个数字,然后将其忽略。 You could use number = int(number) if you wanted to store the result in the number variable. 如果要将结果存储在number变量中,则可以使用number = int(number)

Consider using number = int(num_textbox.get()) to get the conversion out of the way up front. 考虑使用number = int(num_textbox.get())进行转换。 (But note that if the contents of that text box is not a valid number, you'll get an exception.) (但是请注意,如果该文本框的内容不是有效数字,则会出现异常。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NLTK TypeError:&#39;str&#39;和&#39;int&#39;的实例之间不支持&#39;&lt;&#39; - NLTK TypeError: '<' not supported between instances of 'str' and 'int' Flask TypeError:“str”和“int”的实例之间不支持“&lt;” - Flask TypeError: '<' not supported between instances of 'str' and 'int' TypeError:在 Python 中的“str”和“int”实例之间不支持“&gt;” - TypeError: '>' not supported between instances of 'str' and 'int' in Python TypeError:'int'和'str'的实例之间不支持'&lt;=' - TypeError: '<=' not supported between instances of 'int' and 'str' 与“TypeError:'<='在'int'和'str'的实例之间不支持”混淆 - Confused With "TypeError: '<=' not supported between instances of 'int' and 'str'" “TypeError: &#39;&gt;&#39; 在 &#39;int&#39; 和 &#39;str&#39; 的实例之间不受支持”最大值 - "TypeError: '>' not supported between instances of 'int' and 'str'" in max Python-&#39;str&#39;和&#39;int&#39;的实例之间不支持&#39;TypeError:&#39;&lt;=&#39; - Python - 'TypeError: '<=' not supported between instances of 'str' and 'int'' Paramiko TypeError:'int'和'str'的实例之间不支持'&lt;' - Paramiko TypeError: '<' not supported between instances of 'int' and 'str' TypeError: '&lt;=' 在 'str' 和 'int' 的实例之间不支持 - TypeError: '<=' not supported between instances of 'str' and 'int' TypeError: '>' 在 'str' 和 'int' 的实例之间不支持 - TypeError: '>' not supported between instances of 'str' and 'int'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM