I
I
Issue2019-08-25 19:41:34
linux
Issue, 2019-08-25 19:41:34

How to run a python file as administrator?

How to implement launching a python form asking for a password in graphical mode?
I created a shortcut on the desktop, launched it with a double click, in the program the "apply" button does not work and does nothing (except waiting for the password), because there is nowhere to enter the superuser password.
If you run the program in the terminal and click "apply" in the program, then the terminal already asks for a password, everything works as it should, but it's not convenient.
How is a graphical password prompt implemented when starting from a shortcut? I did not find this information in the search engines ...
Here's what I want to use:

#!/usr/bin/python3
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from os import system as go
from os import getcwd as mainpath
from gui import Ui_MainWindow

app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
main_path =   "'{}'".format(str(mainpath()))

def pkg_installer():
 pkg_list = ui.check_list() # Получаем список пакетов необходимых для установки

 go("sudo apt install " + pkg_list) # Здесь выполняется команда и в терминале просит пароль

ui.pushButton_go.clicked.connect( pkg_installer )
sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2019-08-25
@paulenot

Use gksudo for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question