gpt4 book ai didi

python - 如何更改框架的背景 - Tkinter!?

转载 作者:太空宇宙 更新时间:2023-11-03 16:08:25 27 4
gpt4 key购买 nike

我一直在 Python 2.7 中使用 Tkinter 创建一个框架并获得不同的背景!。但是,当我使用此代码时,会出现以下错误:

_tkinter.TclError: unknown option "-bg"

以及完整的回溯:

Traceback (most recent call last):
File "//MCLSERVER4/MCL Sicherung/M.Grbic/Python/Power Cycling Test/pwrMultiCycling.py", line 26, in <module>
gui = Interface(root)
File "//MCLSERVER4/MCL Sicherung/M.Grbic/Python/Power Cycling Test/pwrMultiCycling.py", line 20, in __init__
self.frame = Frame(parent, bg='', colormap='new')
File "S:\Python27\lib\lib-tk\ttk.py", line 735, in __init__
Widget.__init__(self, master, "ttk::frame", kw)
File "S:\Python27\lib\lib-tk\ttk.py", line 555, in __init__
Tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "S:\Python27\lib\lib-tk\Tkinter.py", line 2036, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-bg"

和我的代码:

from Tkinter import *
from ttk import *
import os
from PIL import Image

class Interface:

def __init__(self, parent):
self.parent = parent
parent.title("")
local_directory = os.path.dirname(os.path.realpath(__file__))
self.dataname = "/does/not/exist"

self.frame = Frame(parent, bg='', colormap='new')



if __name__ == '__main__':
root = Tk()
gui = Interface(root)
root.mainloop()

最佳答案

我想,我有一个解决方案,我的问题如下所示:

import Tkinter
from ttk import *
import os

class Interface:

def __init__(self, parent):
self.parent = parent
parent.title("")

self.frame = Tkinter.Frame(parent, bg='', colormap='new')


if __name__ == '__main__':
root = Tkinter.Tk()
gui = Interface(root)
root.mainloop()

关于python - 如何更改框架的背景 - Tkinter!?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39525236/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com