【发布时间】:2021-02-19 17:15:11
【问题描述】:
我正在尝试在 python 中创建一个随机 shell...但问题是我的代码出现错误我试图从我的代码中删除 __commands__[0] 但没有任何结果。
我的错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\User1\Downloads\Stuff\untitled2.py", line 14, in commands
if text in __commands__[0]:
TypeError: 'set' object is not subscriptable
我的代码:
from tkinter import *
def tk_shell(Name=None):
def commands():
__commands__ = {'-v',
'-e',
'+a',
'DATA'}
text = (cmd.get("1.0","end"))
if text in __commands__[0]:
print("version 1.11")
else:
print("NOPE")
tk = Tk()
tk.resizable(width=False, height=False)
tk.geometry('700x490')
tk.title('Server Prompt-'+str(Name))
#main
cmd = Text(tk,bg='black',fg='#00FF00')
cmd.config(height=600,width=480)
cmd.pack()
r_button = Button(tk,width=12,height=2,text='Run',bg='#00FF00',command=commands)
r_button.place(x=610,y=0)
tk.mainloop()
tk_shell()
【问题讨论】:
-
嗨,也许这可能会引起您的兴趣stackoverflow.com/questions/216972/…
-
当您执行
__commands__[0]时,您期望的结果是什么?为什么?