RosettaCodeData/Task/Simple-windowed-application/Python/simple-windowed-application-2.py

23 lines
609 B
Python
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
import tkinter as tk
2013-04-11 01:07:29 -07:00
2019-09-12 10:33:56 -07:00
class ClickCounter(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
tk.Pack.config(self)
self.label = tk.Label(self, text='There have been no clicks yet')
2013-04-11 01:07:29 -07:00
self.label.pack()
2019-09-12 10:33:56 -07:00
self.button = tk.Button(self,
text='click me',
command=self.click)
2013-04-11 01:07:29 -07:00
self.button.pack()
self.count = 0
2019-09-12 10:33:56 -07:00
def click(self):
self.count += 1
self.label['text'] = f'Number of clicks: {self.count}'
if __name__ == "__main__":
2013-04-11 01:07:29 -07:00
ClickCounter().mainloop()