Ad
Two Instances Of Tkinter Window Created When Run Python Script As Administrator
I am developing small app using tkinter UI
which has a windows and a small form with three input and a button.
It requires to run with Administrator privileges (some file operation in C:\
). I use following code and it works fine.
import admin
if not admin.isUserAdmin():
admin.runAsAdmin()
Only problem I face is when I run python script(.py), it creates two instances of same window. Even two Python environment windows(black cmd screen of python.exe) appear.
- UAC dialog appears to ask for permission to run as admin. When I press "Yes", window appears as admin.
- Simple window (same app) but without admin privileges. Appears after closing of 1st window.
I am using Windows 10 and Visual Studio 2015 Pro and Python 2.7.
This is how I initialize UI.
window = Tk()
window.title("User Interface")
.........
.........
# all other code blocks(UI + Business Logic) appear here.
.........
.........
window.mainloop()
Ad
Answer
Just use:
import admin
if not admin.isUserAdmin():
admin.runAsAdmin()
quit()
As I understand, you run the same program (admin.runAsAdmin()
), but you don't close the non-admin one. Use quit()
or sys.exit()
for that.
Hope that's helpful!
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad