0
私は非常に似た疑問を持っている他のスレッドの回答を見ましたが、うまくいかないようです。'Class'オブジェクトには 'tk'属性がありません
class Application(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
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 (Login, Admin):
PageName = F.__name__
frame = F(parent=Container, controller=self)
self.frames[PageName] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(Login)
def show_frame(self, PageName):
frame = self.franes[PageName]
frame.tkraise()
class Login(tk.Frame):
def __init__(self, parent, controller):
super().__init__(self, parent) (...)
フレーム間を切り替えるために、このコードで別のスレッドの回答に従っていました。
エラー:
AttributeError: 'Login' object has no attribute 'tk'
Traceback (most recent call last):
File "G:/Jake/Google Drive/StockControl/Framework/src/Login.py", line 70, in <module>
App = Application()
File "G:/Jake/Google Drive/StockControl/Framework/src/Login.py", line 15, in __init__
frame = F(parent=Container, controller=self)
File "G:/Jake/Google Drive/StockControl/Framework/src/Login.py", line 28, in __init__
super().__init__(self, parent)
File "C:\Utilities\Python\lib\tkinter\__init__.py", line 2738, in __init__
Widget.__init__(self, master, 'frame', cnf, {}, extra)
File "C:\Utilities\Python\lib\tkinter\__init__.py", line 2286, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Utilities\Python\lib\tkinter\__init__.py", line 2256, in _setup
self.tk = master.tk
AttributeError: 'Login' object has no attribute 'tk'
任意の助けをいただければ幸いです、ありがとうございました! (Python 3.6)
どのラインでエラーが発生しますか? – Daniel
それはdoesntです。 'tk'はモジュールであり、あなたが継承している' tk.Frame'にはその属性がありません。 –
エラーを取得している行が指定されていません。 @ダニエル – Jake