pythonでguiを実際に組みながら勉強しているものです。
ファイルダイアログでファイルを読み込むguiを作りたいと思い、下のようなコードを組みました。
実行すると
Traceback (most recent c~~~~all last):
File "<stdin>", line 2, in <module>
File "<stdin>", line 8, in main
File "<stdin>", line 6, in init
File "/Applications/anaconda/lib/python3.6/tkinter/init.py", line 2366, in init
Widget.init(self, master, 'button', cnf, kw)
File "/Applications/anaconda/lib/python3.6/tkinter/init.py", line 2289, in init
BaseWidget._setup(self, master, cnf)
File "/Applications/anaconda/lib/python3.6/tkinter/init.py", line 2259, in _setup
self.tk = master.tk
AttributeError: 'top_page' object has no attribute 'tk'
と言うエラーがでたのですが、今までのエラーと違い、どこがどうなっているのかわかりません。
ネットでも色々調べて見ましたが、よくわからず、ここに質問させていただきました。
どなたか教えていただけるとありがたいです。
python
1import tkinter as tk 2import tkinter.filedialog as tkfd 3import os 4 5 6class top_page(tk.Frame): 7 8 def __init__(self,master=None,cnf={},**kw): 9 self.dir_path = "" 10 11 self.button = tk.Button(self, text = "データ読み込み", command = lambda: self.data_command()) 12 self.button.pack() 13 14 def data_command(self): 15 fTyp = [("csv file","CSV")] 16 iDir = os.path.abspath(os.path.dirname("__file__")) 17 file = tkfd.askopenfilename(filetypes = fTyp,initialdir = iDir) 18 19def main(): 20 root = tk.Tk() 21 root.title("test") 22 root.geometry("800x600") 23 lbl_name = tk.Label(root, text ="software_name" , font=("", 50)) 24 lbl_name.place(x=230, y=0) 25 26 top_page(root) 27 28 root.mainloop() 29 30if __name__ == '__main__': 31 main()
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。