開発環境
- macOS Catalina - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.8 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 16(Creating Graphical User Interfaces)、Exercise 1、2の解答を求めてみる。
コード
#!/usr/bin/env python3
import tkinter
print('1.')
app = tkinter.Tk()
button = tkinter.Button(app, text="Goodbye.", command=app.destroy)
button.pack()
app.mainloop()
print('2.')
class Counter:
def __init__(self, parent):
self.parent = parent
# Model
self.count = tkinter.IntVar(0)
# View
self.button = tkinter.Button(self.parent,
textvariabl=self.count,
command=self.count_up)
self.button.pack()
# Controller
def count_up(self):
self.count.set(self.count.get() + 1)
app = tkinter.Tk()
counter = Counter(app)
app.mainloop()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample1.py
1.
2.
%
0 コメント:
コメントを投稿