0

I want to make an application, that uses Bash commands, but everytime it results in Exception in Tkinter callback.

I already have tried to use subprocess popen but there it even wanted to start the commands.

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 except the button changes to "Aktualisiert" and not the actual Exception error.

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
2
  • What is the sample output for the sudo -S pacman -Syu? Do you intend to pass the output of that command as an argument for the function update_button.config? Commented Sep 28, 2019 at 23:36
  • The output should be like in the image: linuxhint.com/wp-content/uploads/2017/12/vb-1.png or it updates some packages when there is an update. And I want that it does "sudo pacman -Syu" when I press the "Aktalisieren" button, so yes Commented Sep 28, 2019 at 23:47

1 Answer 1

1

You don't need to pass the os.system('sudo -S pacman -Syu') call as an argument for the update_button.config for it to run. You just need to call it somewhere inside the button_action function, which will be triggered when "Aktalisieren" button is clicked as specified in line update_button = Button(fenster, text="Aktualisieren", command=button_action).

def button_action():
    os.system('sudo -S pacman -Syu')
    update_button.config(text="Aktualisiert!")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.