Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

python - Tkinter transparentcolor working with .py but not with .pyw

root.attributes("-transparentcolor", "white") won't work with a .pyw file extension

Up until yesterday all my tkinter GUIs have been working like they should but two days ago all of them stopped working like I want them to. The line root.attributes("-transparentcolor", "white") has always made the white color transparent, like it should, but now it doesn't work like it used to. It does work properly if I launch the program with a .py file extension but not with a .pyw. Obviously I don't want a console window to open along with all of my programs so this is not something I could just accept. Like I said, this has worked fine up until yesterday.

For the past day I've been doing all kinds of things to try to fix this, I even uninstalled python completely and reinstalled the latest version, but nothing has changed my problem.

I'm on Windows 10 and python 3.9.1 right now (after the reinstall, cant remember what version I had before)

I didn't do a single thing that could've made this happen, I didn't update or change anything before my problem showed up, I simply started my computer in the morning like always.

Does anyone have any clue on what I could try? Could anyone try to do the same thing and see if it works for you?

Code below creates a tkinter window with a transparent background if saved as a .py file, but creates a tkinter window with white background if saved like a .pyw file.

from tkinter import *

root = Tk()

root.config(bg= 'white')
root.attributes('-transparentcolor', 'white')

root.mainloop()

Update: Hmm... I've discovered something interesting! If i start my program through cmd prompt with pythonw my problem still appears, but if i do the same thing with a cmd prompt running as administrator it all works like before, I get a transparent background!

Update 2: I've set pythonw.exe to always run as administrator, and this solves my problem. But if I do that I always get a uac prompt wich I never got before, so I haven't fixed my problem, I've just found a tedious workaround.

question from:https://stackoverflow.com/questions/65952507/tkinter-transparentcolor-working-with-py-but-not-with-pyw

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Allrighty then... I've found a sollution, even though I do not like it. I don't have anything against windows or microsoft, but I really do not like the microsoft store. But I have to give in, this does solve my problem: I went and installed python 3.9 from the microsoft store. I do not know why I did it. I do not know why it helped. I started my .pyw file with the installed program/app called "Python 3.9 (Windowed)" and badaboom, badabing, my problem for some frickin reason, dissapeared... I don't know if this is a viable sollution long term (or at all for that matter) but it solves my problem, and after 2 days of continously smashing my head against the keyboard and wanting to set my pc on fire, I have to accept this as a sollution and move on...

Thank u @acw1668 and @martineau for trying to help, I really appreciate it!

Tl;dr: Download python from microsoft store and use that program to start the file


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...