所以我现在正在尝试做一个程序,允许我输入一个字符串,然后输出到tkinter的文本窗口中。但是,当在simpledialog.askstring窗口中按下'cancel‘按钮时,我收到一条错误消息。
这是我在Python Shell中得到的错误消息:
_tkinter.TclError: wrong # args: should be ".!text insert index chars ?tagList chars tagList ...?"
我只想让程序在按下取消按钮时什么也不做。:(
from tkinter import *
from tkinter import simpledialog
import tkinter.messagebox
class Thing:
def __init__(self):
global buttonThing
global window
window = Tk()
frame1 = Frame(window)
frame1.pack()
buttonThing = Button(frame1, text = "click me", command = self.clickMe)
buttonThing.pack()
self.text =Text(window)
self.text.pack()
window.mainloop()
def clickMe(self):
uwu = simpledialog.askstring("hey","put stuff")
self.text.insert(END, uwu)
Thing()
发布于 2019-04-19 07:46:52
当您按“取消”时,对话框返回“无”,而当您试图在文本控件中插入“无”时,错误仍然存在。
所以用下面的代码替换这个代码self.text.insert(END, uwu)
if uwu:
self.text.insert(END, uwu)
https://stackoverflow.com/questions/55754870
复制相似问题