Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

python用TKインターフェイスtkinter その2:画面サイズとタイトル

タイトルだとか画面のサイズといった全体に関わることはtkのrootで設定します。

実際のところ

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=root.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
root.title(u"My Apps") # タイトル
root.geometry("420x360") #画面サイズ ピクセル単位
app = Application(master=root)
app.mainloop()

出る画面はこんな感じ
f:id:shuzo_kino:20200305235642p:plain