【问题标题】:Why does an IF in python outputs an error?为什么python中的IF会输出错误?
【发布时间】:2020-01-30 10:02:32
【问题描述】:

我在 tkinter 中做了一个小程序,但它不起作用,因为当我按 F5 执行代码时,会出现一个弹出窗口说:Tab/space error .这是我的代码:

def codigo():
global text2
f2=Frame(f, width=300, height=500)
f2.pack()
f2.config(bg='dark grey')
text2=Label(f, text=spin.get(), font=('Arial Bold', 90), bg=('dark grey'))
text2.place(x=80, y=200)
timer.current = int(spin.get())
timer()
if text2 == 0:
    timerc = int(spin3.get())
    timer2()
text3=Label(f, text=int(spin3.get()), font=('Arial Bold', 30), bg=('dark grey'))
text3.place(x=200, y=350)
text4=Label(f, text=spin4.get(), font=('Arial Bold', 30), bg=('dark grey'))
text4.place(x=170, y=400)
text5=Label(f, text='Ejercicios:', font=('Arial Bold', 30), bg=('dark grey'))
text5.place(x=5, y=350)
text6=Label(f, text='Rondas:', font=('Arial Bold', 30), bg=('dark grey'))
text6.place(x=5, y=400)
if text2==0:
    text3(text=(int(spin3.get())-1))        

问题出在text3(text=(int(spin3.get())-1)),但我不知道为什么。

谢谢。

【问题讨论】:

  • 确保您始终使用空格而不是制表符。也请不要粘贴错误的图像。无法搜索。
  • @tomgalpin 我使用的是制表符,而不是空格。我尝试使用空格,输出是一样的
  • 是的,尝试使用适当的空格。
  • @Kartheek 你是什么意思?
  • @Kartheek 谢谢,它成功了!我只使用标签

标签: python python-3.x tkinter tabs spaces


【解决方案1】:

有更正的代码:

def codigo():
    global text2
    f2=Frame(f, width=300, height=500)
    f2.pack()
    f2.config(bg='dark grey')
    text2=Label(f, text=spin.get(), font=('Arial Bold', 90), bg=('dark grey'))
    text2.place(x=80, y=200)
    timer.current = int(spin.get())
    timer()
    if text2 == 0:
        timerc = int(spin3.get())
        timer2()
    text3=Label(f, text=int(spin3.get()), font=('Arial Bold', 30), bg=('dark grey'))
    text3.place(x=200, y=350)
    text4=Label(f, text=spin4.get(), font=('Arial Bold', 30), bg=('dark grey'))
    text4.place(x=170, y=400)
    text5=Label(f, text='Ejercicios:', font=('Arial Bold', 30), bg=('dark grey'))
    text5.place(x=5, y=350)
    text6=Label(f, text='Rondas:', font=('Arial Bold', 30), bg=('dark grey'))
    text6.place(x=5, y=400)
    if text2==0:
        text3(text=(int(spin3.get())-1))

【讨论】:

  • 我抄错了,抱歉。我编辑了它。在代码中,标签只是我需要的
猜你喜欢
  • 2020-12-24
  • 2023-02-11
  • 2021-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-17
相关资源
最近更新 更多