Tkinter transparentcolor working with .py but not with .pyw

1.1k Views Asked by At

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, can't 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 which I never got before, so I haven't fixed my problem, I've just found a tedious workaround.

1

There are 1 best solutions below

0
On

Allrighty then... I've found a solution, 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, disappeared...

I don't know if this is a viable solution long term (or at all for that matter) but it solves my problem, and after 2 days of continuously smashing my head against the keyboard and wanting to set my pc on fire, I have to accept this as a solution 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