Hello.
I’m trying to make a small application with Gtk and Python.
Application has a basic user interface to do job of apt command line tool. update upgrade etc.
I want to use apt python API.
But my current user is not root and i dont want to run my application with sudo.
I want to pop a dialog for user to enter root password and give permission to application to run few functions for a while.
There is a GTK.LockButton widget and found some examples about it.
Implemented on my code and tried to run update function from apt.Cache.
Still got permission error. But permission.get_allowed() returned True.
Is there any guide for this usage? How can i handle root permission authentication on GTK applications in a better way?
Thanks
To get a dialog that prompts for the root password you can use pkexec
instead of sudo
. So a simple way to do it with a python script is use Gio.Subprocess
to spawn the command using pkexec
.
GtkLockButton
is only really used to interact with policykit actions, you probably don’t want to use that unless you already know that you need those actions (i.e. you need to deploy a separate service that implements the action)