如何修改.textinput中的按钮?

2024-10-01 15:34:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做菜单之类的

代码如下:

from turtle import TurtleScreen, RawTurtle, TK

root = TK.Tk()
root.title("ArMoon")
canvas = TK.Canvas(root, width=1000, height=700)
canvas.pack()
win = TurtleScreen(canvas)
dali = RawTurtle(win)

def Entrada():
    return win.textinput("Figura"," 1. Operando\n 2. Sumar operandos\
    \n 3. Reiniciar\n 4. Salir\n ")



while True:
    x = Entrada()
    if x == "4" or x == "":
        break
    oper = x.split()
    print(oper)
    x = oper[0]
    print(x)
    #if x <= 0:



win.mainloop()

问题是,当我运行程序时,在文本输入的小窗口中,它们向我显示两个按钮,我不介意,我喜欢它们,但有没有办法修改它们的功能

“确定”按钮似乎工作正常,但当我按下“取消”按钮,我得到一个错误

> Traceback (most recent call last):
> 
>   File "C:\Users\Lobo\Desktop\TORTUGA\Borrador v2.py", line 21, in
> <module>
> 
>     oper = x.split()
> 
> AttributeError: 'NoneType' object has no attribute 'split'

我想修改它,所以当我按下它只是运行'打破'结束


Tags: 代码fromif菜单root按钮wintk

热门问题