python - How do I change the background of a Frame in Tkinter? -
i have been creating email program using tkinter, in python 3.3. on various sites have been seeing frame widget can different background using frame.config(background="color"). however, when use in frames gives following error:
_tkinter.tclerror: unknown option "-background" it not work when doing following:
frame = frame(root, background="white") or:
frame = frame(root) frame.config(bg="white") i can't figure out. post whole source code dont want exposed on internet, frame creation goes this:
mail1 = frame(self, relief=sunken) mail1.pack() mail1.place(height=70, width=400, x=803, y=109) mail1.config(background="white") i have tried multiple options trying modify background. frame wrap around email preview inbox.
in case it's needed, way importing modules:
import tkinter, time, base64, imaplib, smtplib imaplib import * tkinter import * tkinter.ttk import * the following full traceback:
traceback (most recent call last): file "c:\users\wessel\dropbox\python\main\class ginomail.py", line 457, in <module> main() file "c:\users\wessel\dropbox\python\main\class ginomail.py", line 453, in main app = application(root) #start application root parent file "c:\users\wessel\dropbox\python\main\class ginomail.py", line 60, in __init__ self.initinbox() file "c:\users\wessel\dropbox\python\main\class ginomail.py", line 317, in initinbox mail1.config(bg="white") file "c:\python33\lib\tkinter\__init__.py", line 1263, in configure return self._configure('configure', cnf, kw) file "c:\python33\lib\tkinter\__init__.py", line 1254, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) _tkinter.tclerror: unknown option "-bg" gives following error code answer:
file "c:\users\wessel\dropbox\python\main\class ginomail.py", line 317, in initinbox mail1 = frame(self, relief=sunken, style='myframe') file "c:\python33\lib\tkinter\ttk.py", line 733, in __init__ widget.__init__(self, master, "ttk::frame", kw) file "c:\python33\lib\tkinter\ttk.py", line 553, in __init__ tkinter.widget.__init__(self, master, widgetname, kw=kw) file "c:\python33\lib\tkinter\__init__.py", line 2075, in __init__ (widgetname, self._w) + + self._options(cnf)) _tkinter.tclerror: layout myframe not found solved! thanks. inbox bar right, background needed white. 
the root of problem unknowingly using frame class ttk package rather tkinter package. 1 ttk not support background option.
this main reason why shouldn't global imports -- can overwrite definition of classes , commands.
i recommend doing imports this:
import tkinter tk import ttk then prefix widgets either tk or ttk :
f1 = tk.frame(..., bg=..., fg=...) f2 = ttk.frame(..., style=...) it becomes instantly obvious widget using, @ expense of tiny bit more typing. if had done this, error in code never have happened.
Comments
Post a Comment