如何在Tkinter激活darkMode时动态修改tk.Frame的背景色
Fixing the Frame Background in Dark Mode
No problem at all—you just missed updating the Application frame itself in your darkMode method! Right now you're updating all the child widgets and the root window, but the frame that holds them all still has its original white background.
Here's how to tweak your darkMode method to fix that:
def darkMode(self): # Update the Application frame's background to match dark mode self.config(bg="#404040") # Your existing widget styling updates self.question.config(bg="#404040", fg="white") self.answercheck.config(bg="#404040", fg="white") self.ocontinue.config(highlightbackground="#404040") self.option1.config(highlightbackground="#404040", highlightthickness=2) self.option2.config(highlightbackground="#404040", highlightthickness=2) self.option3.config(highlightbackground="#404040", highlightthickness=2) self.option4.config(highlightbackground="#404040", highlightthickness=2) self.QUIT.config(highlightbackground="#404040") root.config(bg="#404040")
Quick explanation:
Since your Application class inherits directly from tk.Frame, the self variable is exactly that frame instance. Calling self.config(bg="#404040") updates its background color to match the rest of your dark mode setup, eliminating any leftover white areas from the frame container itself.
内容的提问来源于stack exchange,提问作者codereeee
相关产品推荐
相关产品推荐

