初入Python,问问各位大佬怎么调用root授权窗口
Tofloor
poster avatar
星外之神
deepin
2017-05-13 21:35
Author
如题,Python-Qt5怎么调用root授权窗口,
Reply Favorite View the author
All Replies
avatar
q_q
deepin
2017-05-13 21:55
#1
不知道。。。
Reply View the author
avatar
星外之神
deepin
2017-05-13 22:17
#2
Reply View the author
avatar
Deepin大法好
deepin
2017-05-13 23:09
#3
同求,想自己写个小插件https://bbs.deepin.org/user/48640
Reply View the author
avatar
linux0208
deepin
2017-05-14 00:20
#4
你可以研究一下pkexec命令
Reply View the author
avatar
rekols
deepin
2017-05-14 00:35
#5
不知道      
Reply View the author
avatar
linux0208
deepin
2017-05-14 01:54
#6
本帖最后由 linux0208 于 2017-5-13 17:56 编辑

pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY  你程序的绝对路径
Reply View the author
avatar
nevershow
deepin
2017-05-14 03:37
#7
from subprocess import Popen, PIPE
p = Popen('gksu command -m 输入密码以执行操作', shell = True, stdout = PIPE)
p.wait()
Reply View the author
avatar
Feng Yu
deepin
2017-05-14 04:25
#8
我的建议是不要这么麻烦,直接给出错误提示,告诉用户必须使用root权限执行即可。

如果你的程序是命令行程序,直接判断下当前用户的pid是不是0,否则给出用户提示,必须使用管理员身份运行,至于用户用的是sudo还是su就不管了。

如果是图形界面程序,在图形界面的执行命令上使用gksudo调用你的程序就完了,比如gparted就这么干的,你内部程序根本无需切换root
Reply View the author
avatar
星外之神
deepin
2017-05-14 05:08
#9
rekols 发表于 2017-5-13 16:35
不知道

大神最近在玩什么?
Reply View the author
avatar
wangyong
deepin
2017-05-14 05:22
#10
gksu 加上你写的程序的名字
Reply View the author
avatar
q1377195627
deepin
2017-05-14 09:55
#11
我也想知道,不过我用的是c++/qt
Reply View the author
avatar
iammsf
deepin
2017-05-14 11:09
#12
最簡單的,apt install gksu,然後把程序拖個桌面圖標出來,在屬性→命令那一行的最前面加上gksu即可,整個程序在只會在運行之前獲取一次root權限,運行過程中再也不需要額外的root授權了
Reply View the author