simple clicker in python

Here's a simple clicker program in Python using the tkinter module for the GUI:

main.py
import tkinter as tk

class Clicker:
    def __init__(self):
        self.count = 0

        self.window = tk.Tk()
        self.window.title("Clicker")

        self.label = tk.Label(self.window, text="Clicks: 0")
        self.label.pack()

        self.button = tk.Button(self.window, text="Click me!", command=self.increment_count)
        self.button.pack()

    def run(self):
        self.window.mainloop()

    def increment_count(self):
        self.count += 1
        self.label.config(text="Clicks: {}".format(self.count))

clicker = Clicker()
clicker.run()
567 chars
25 lines

The program creates a Clicker class with a counter variable count. In the constructor, it initializes the GUI using tkinter. The window and label are created with tk.Label and tk.Button, respectively. The button has a command which is set to the increment_count method of the Clicker class.

When the button is clicked, increment_count is called which increments the count variable and sets the text of the label to reflect the new count.

The program can be executed by creating a Clicker instance and calling its run method.

gistlibby LogSnag