0
コードを学習するために、コードを書き直して練習しています。今私はここで何が起こっているのかをよく理解していますが、私はこの特定のコードセットでこのエラー(以下に示す)を得ています。エラー! tkinter.TclError:フレームを開くときに "-parent"の不明なオプションTkinter Py3.6
これは他のものとやっておらず、変数名からかなり離れています。しかし、私はそれが問題だと思って、iveは、そのような変数に組み込まれている変数名を変更しました。例えば
I以下のコードの前には、これは私の書いたコードであるframeContainer
だけではなくcontainer
、およびF
はなくn_frame
Traceback (most recent call last):
File "C:/Users/nasto/Desktop/CMS.py", line 40, in <module>
app = frame_store()
File "C:/Users/nasto/Desktop/CMS.py", line 14, in __init__
frame = n_frame(parent=container, controller=self)
File "C:\Users\nasto\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2738, in __init__
Widget.__init__(self, master, 'frame', cnf, {}, extra)
File "C:\Users\nasto\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2293, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-parent"
を持っていました。
import tkinter as tk
class frame_store(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
'''container is used so that all the frames can be stacked, from there we can call other frames within the container to the top, to the current active frame'''
container = tk.Frame(self)
container.pack(side='top', fill='both', expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for n_frame in (login_frame, overview_frame, accounting_frame):
pageName = n_frame.__name__
frame = n_frame(parent=container, controller=self)
self.frames[pageName] = frame
frame.grid(row=0, column=0, sticky='nsew')
self.show_frames('login_frame')
def show_frames(self, pageName):
frame = self.frames[pageName]
self.update_idletasks()
self.state('zoomed')
self.title('a title')
frame.tkraise()
class login_frame (tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
labelOne = tk.Label(self, text='Start Frame').grid(row=1, column=1)
class overview_frame(tk.Frame):
pass
class accounting_frame(tk.Frame):
pass
if __name__ == "__main__":
app = frame_store()
app.mainloop()
その他のコードあなたはparent
がFrame
のための有効なオプションではありません、ただ、エラー状態のように見えるに
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
self.update_idletasks()
self.state('zoomed')
self.title('A2 Project Finances')
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.userID = tk.Button(self, text = 'User ID ').grid(row=1,column=0)
ライフセーバー、おかげでチームメイトを:それはいくつかのウィンドウではなく、他人のために起こる
理由は他にはないのに対し、一つのウィンドウが明示的に
parent
パラメータを宣言することです! –