我正在尝试从我正在使用的 python 代码中执行一个 python 文件。
这是我的代码:
from tkinter import *
def send():
exec(open('usersend.py').read())
with open("User_Data.txt") as f:
lines = f.read() ##Assume the sample file has 3 lines
second = lines.split()[2]
root = Tk()
label = Label(root, text='Welcome, ' + second + ' to Jammer!')
label.config(font=('Courier', 44))
label.pack()
button = Button(root, text='Send a game', command = send)
button.config(font=('Courier', 10))
button.pack(side = 'bottom', expand = False, padx = 4, pady = 4)
但是当我运行它时,我收到以下错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/home/pi/saish/programs/User2.py", line 5, in send
exec(open('usersend.py').read())
File "<string>", line 6, in <module>
File "/usr/lib/python3/dist-packages/thonny/plugins/cpython/cpython_backend.py", line 1205, in readline
return self._generic_read("readline", limit)
File "/usr/lib/python3/dist-packages/thonny/plugins/cpython/cpython_backend.py", line 1193, in _generic_read
"Wrong type of command (%r) when waiting for input" % (msg,)
RuntimeError: Wrong type of command (ToplevelCommand(source='dfgdfg\n', tty_mode=True, id='cmd_13', local_cwd='/home/pi/saish/programs', expected_cwd='/home/pi/saish/programs', name='execute_source', argv=[])) when waiting for input
我希望能够成功运行此代码。