Pythonのtkinterで以下のようなプログラムをつくりました。
Python
1import tkinter as tk 2 3root = tk.Tk() 4root.geometry("300x300") 5frame1 = tk.Frame(root,width = 100,height = 100,bg = "red") 6frame2 = tk.Frame(root,widht = 100,height = 100,bg = "blue") 7 8root.mainloop()
上記を実行すると、rootウィンドウに、frame1、frame2が上下に色違いで配置されます。
これと同じことを、オブジェクト指向(下記プログラム、ネットや参考書などにサンプルとして
記載されていることがある)で書くにはどのようにしたらよいのでしょうか?
Python
1import tkinter as tk 2class App( tk. Frame): 3 def __init__( self, master = None): 4 super().__ init__( master) 5 master. title(" テキスト ボックス 内容 の 取得") 6 master. geometry(" 350 x 150") self. pack() 7 8root = tk.TK() 9root = App(master = root) 10 11root.mainloop()
回答1件
あなたの回答
tips
プレビュー
2019/05/17 22:09