ヘディングのテキスト
前提・実現したいこと
pytonのtkinterを使用して、ウィンドウの表示、ボタンの配置を行いたいです。
発生している問題・エラーメッセージ
_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack
該当のソースコード
Python
1import tkinter as tk 2from tkinter import ttk 3 4class Window(tk.Frame): 5 def __init__(self, master, title, geometry,frame): 6 super().__init__(master) 7 self.pack() 8 master.geometry(geometry) 9 master.title(title) 10 master.resizable(0,0) 11 master.grid_columnconfigure(0, weight=1) 12 master.grid_rowconfigure(0, weight=1) 13 14 frame = ttk.Frame(master,style = 'TFrame',) 15 frame.grid(row=0, column=0, sticky='nwse') 16 frame.grid_columnconfigure((0, 1), weight=1) 17 frame.grid_rowconfigure((0, 1, 2, 3, 4), weight=1) 18 19 def Button(self,frame,button_name,text,width,x_position,y_position,action=None): 20 button_name = tk.Button(frame,text=text, width=width) 21 button_name.place(x=x_position,y=y_position) 22 if action==quit: 23 def close(a): 24 self.quit() 25 button_name.bind("<Button-1>", close) 26 27def main(): 28 pokeda = tk.Tk() 29 pokeda = Window(pokeda,"ポケ打","400x300","frame1") 30 pokeda.Button("frame1","a","たたかう",10,100,150) 31 pokeda.Button("frame1","b","にげる",10,200,150,quit) 32 pokeda.mainloop() 33 34 35if __name__ == "__main__": 36 main()
試したこと
frameを使用する前までは実行できていたのですが、小回りを利かせるために使用したところ上記のエラーがでました。エラーの意味は理解できますが、理由がどうしてもわかりません。
補足情報(FW/ツールのバージョンなど)
まだプログラミングを初めて一週間にも満たないため、とんちんかんなことを言っている(している)、かもしれませんがどうかご容赦ください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/06 05:12