LoginSignup
1
0

More than 5 years have passed since last update.

Tkinter を初めて使ってみた

Last updated at Posted at 2018-05-10

Tkinter とは?

簡単に言えば,Python を使った GUI 構築ツール,と考えていたら良いと思います.

空の画面を表示する

まずは,空の画面を表示してみます.

test1.py
import tkinter as tk

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

root = tk.Tk()
root.title("Title")
root.geometry("150x100")
app = Application(master=root)
app.mainloop()

Hello World! を出力

次にターミナルの画面上に Hello World! と表示させるボタンを作ります.

test2.py
import tkinter as tk

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

    def create_button(self):
        self.button = tk.Button(self, text="click\nme", command=self.func)
        self.button.pack(side="top")

    def func(self):
        print("Hello World!")

root = tk.Tk()
root.title("Title")
root.geometry("150x100")
app = Application(master=root)
app.mainloop()

まだまだ,簡単にしか触れていないですが,
今後また発展させていきたいです.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0