'Fading a window to a specific color in tkinter
Im making a transition screen in Tkinter between the loading screen and the actual inteface, and my desired behaviour is for the entire window fade to a shade of black, resize itself to the size of the inteface, before fading back in to the interface. The things I saw with root.attribute would not work because it would simply turn the screen transparent which is not what I want. This is the code I have so far, except I dont have the fading part.
import tkinter as tk
moduleImportList = [
'from keras.models import Sequential',
'from keras.layers import Dense',
'import pandas as pd',
]
class mainGUI:
def __init__(self, master):
self.master = master
master.title('Loading screen test')
master.config(bg="#1f1f1f")
master.resizable(False,False)
master.geometry('300x100')
master.eval('tk::PlaceWindow . center')
self.loadingScreen = tk.Label(master,text='Loading...',font=('ariel 30 bold'),bg='#1f1f1f',fg='white')
self.loadingScreen.pack(pady=20)
self.loadModules()
self.fadeAndResize(master)
def loadModules(self):
for i in moduleImportList:
root.update()
exec(i)
print('module loaded')
def fadeAndResize(self, master):
initHeight, initWidth = master.winfo_height(),master.winfo_width()
for i in range(200):
Nwidth = initWidth + (800-initWidth)/200*(i+1)
Nheight = initHeight + (500-initHeight)/200*(i+1)
master.geometry("{}x{}".format(round(Nwidth),round(Nheight)))
root.update()
root = tk.Tk()
mainWindow = mainGUI(root)
root.mainloop()
(also if there's a way for it to resize about the middle of the screen that would be nice too)
Edit: After viewing a bunch of other posts, I have come to the conclusion that messing around with transparency would not get me anywhere, so the next thing I can think of is to change the colors of everything within a frame to be the same as the background so it's virtually indistinguishable or to have some sort of canvas etc covering everything else, not sure how to implement that tho.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|