Python “如何修复”';int';“对象不可编辑”;tkinter中的错误
我想创建一个使用Bash命令的应用程序,但每次它都会导致Tkinter回调异常 我已经尝试过使用subprocess popen,但它甚至想启动这些命令Python “如何修复”';int';“对象不可编辑”;tkinter中的错误,python,tkinter,Python,Tkinter,我想创建一个使用Bash命令的应用程序,但每次它都会导致Tkinter回调异常 我已经尝试过使用subprocess popen,但它甚至想启动这些命令 from tkinter import * import os # The following commands gets executed, if the user is pressing the action button def button_action(): update_button.config(os.system('
from tkinter import *
import os
# The following commands gets executed, if the user is pressing the action button
def button_action():
update_button.config(os.system('sudo -S pacman -Syu'), text="Aktualisiert!")
# create a window
fenster = Tk()
# set the title of the window
fenster.title("Befehlsammlung")
# create button and labels
update_label = Label(fenster, text="Drücke auf Aktualisieren, um alle Pakete zu updaten.",)
update_button = Button(fenster, text="Aktualisieren", command=button_action)
exit_button = Button(fenster, text="Schließen", command=fenster.quit)
# Add your components in your favourite
update_label.pack()
update_button.pack()
exit_button.pack()
# wait for input
fenster.mainloop()
I除了按钮更改为“Aktualisiert”之外,没有实际的异常错误
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 106, in _cnfmerge
cnf.update(c)
TypeError: 'int' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/home/flozge/PycharmProjects/untitled1/GUI.py", line 7, in button_action
update_button.config(os.system('sudo -S pacman -Syu'), text="Aktualisiert!")
File "/usr/lib/python3.7/tkinter/__init__.py", line 1485, in configure
return self._configure('configure', cnf, kw)
File "/usr/lib/python3.7/tkinter/__init__.py", line 1469, in _configure
cnf = _cnfmerge((cnf, kw))
File "/usr/lib/python3.7/tkinter/__init__.py", line 109, in _cnfmerge
for k, v in c.items():
AttributeError: 'int' object has no attribute 'items'
Process finished with exit code 0
您不需要将
os.system('sudo-S pacman-Syu')
调用作为update\u button.config
的参数传递给它即可运行。您只需在按钮\动作
函数中的某个地方调用它,当按更新按钮=按钮(fenster,text=“Aktualisieren”,command=按钮\动作)
行中的规定单击“Aktalisieren”按钮时,将触发该函数
sudo-S pacman-Syu的示例输出是什么?是否要将该命令的输出作为函数
update\u button.config
的参数传递?该输出应与图像中的一样:或者在有更新时更新某些包。我想当我按下“Aktalisieren”按钮时,它会显示“sudo pacman-Syu”,所以是的
def button_action():
os.system('sudo -S pacman -Syu')
update_button.config(text="Aktualisiert!")