質問編集履歴
1
コメントアウトで機能を記載。
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,10 +18,12 @@
|
|
18
18
|
```python
|
19
19
|
import tkinter as tk
|
20
20
|
|
21
|
+
# rootウィンドウの作成
|
21
22
|
root = tk.Tk()
|
22
23
|
root.title("TkTrain")
|
23
24
|
root.geometry("400x300")
|
24
25
|
|
26
|
+
# ボタンが配置されたフレーム作成のためのクラスを定義
|
25
27
|
class ButtonFrame(tk.Frame):
|
26
28
|
def __init__(self, master=None, bg=None, text=None, width=None, height=None):
|
27
29
|
super().__init__(master, bg=bg, width=width, height=height)
|
@@ -32,14 +34,18 @@
|
|
32
34
|
self.place_forget()
|
33
35
|
new_frame.grid(row=0, column=0, sticky=tk.NSEW)
|
34
36
|
|
37
|
+
# frame1のインスタンス化及びボタンコマンドの設定
|
35
38
|
frame1 = ButtonFrame(root, bg="red", text = "button1", width=200, height=300)
|
36
39
|
frame1.button["command"] = lambda: frame1.switch_frame(frame2)
|
37
40
|
|
41
|
+
# frame2のインスタンス化及びボタンコマンドの設定
|
38
42
|
frame2 = ButtonFrame(root, bg="blue", text = "button2", width=200, height=300)
|
39
43
|
frame2.button["command"] = lambda: frame2.switch_frame(frame1)
|
40
44
|
|
45
|
+
# frame1の初期配置
|
41
46
|
frame1.grid(column=0, row=0, sticky=tk.NSEW)
|
42
47
|
|
48
|
+
# メインループ(gridの行列が2以上になった時用にfor文で記述しています。)
|
43
49
|
for i in range(1):
|
44
50
|
root.grid_columnconfigure(i, weight=1)
|
45
51
|
|