[Python] How do I output the number of times a certain button was clicked in the shell in...

Discussão em 'Python' iniciado por Stack, Agosto 15, 2025.

  1. Stack

    Stack Membro Participativo

    So my GUI is fully functional except I would like to be able to keep a counter in the console of how many times each different button was clicked (e.g "the like button was clicked x times" & "the um button was clicked y times"). I've tried unsuccessfully, my problem is that nothing is actually printing in the console.

    Can someone point out how to properly execute this? Thank you.

    from tkinter import *
    import tkinter as tk


    window = tk.Tk()
    window.geometry('900x900')
    window.config(bg = 'honeydew2')
    window.title('The Speech Filler Counter')

    like = 0
    def likes():
    global like
    like = like + 1
    likelabel.configure(text=like)

    likelabel = tk.Label(window, text = like, bg = 'honeydew2', fg = 'red')
    likelabel.place(x = 22, y = 1)


    likebutton = tk.Button(window, text="Like", activebackground= 'blue', activeforeground = 'honeydew2', bg = 'deep sky blue', fg = 'red', command=likes).place(x= 2, y = 25)


    um = 0
    def ums():
    global um
    um = um + 1
    umlabel.configure(text = um)

    umlabel = tk.Label(window, text = um, bg = 'honeydew2', fg = 'cyan')
    umlabel.place(x = 122, y = 1 )

    umbutton = tk.Button(window, text="Um", activebackground= 'brown', activeforeground = 'honeydew2', bg = 'light pink', fg = 'blue', command=ums).place(x= 100, y = 25)

    basically = 0
    def basicallys():
    global basically
    basically = basically + 1
    baslabel.configure(text = basically)

    baslabel = tk.Label(window, text = basically, bg = 'honeydew2', fg = 'deep pink')
    baslabel.place(x = 235, y = 1 )

    basbutton = tk.Button(window, text="Basically", activebackground= 'red', activeforeground = 'black', bg = 'gold', fg = 'brown', command=basicallys).place(x= 200, y = 25)

    uh = 0
    def uhs():
    global uh
    uh = uh + 1
    uhlabel.configure(text = uh)

    uhlabel = tk.Label(window, text = uh, bg = 'honeydew2', fg = 'lime green')
    uhlabel.place(x = 350, y = 1 )

    uhbutton = tk.Button(window, text="Uh", activebackground= 'purple2', activeforeground = 'goldenrod1', bg = 'firebrick1', fg = 'blue2', command=uhs).place(x= 335, y = 25)

    youknow = 0
    def youknows():
    global youknow
    youknow = youknow + 1
    youknowlab.configure(text = youknow)

    youknowlab = tk.Label(window, text = youknow, bg = 'honeydew2', fg = 'SlateBlue1')
    youknowlab.place(x = 455, y = 1 )

    youknowbutton = tk.Button(window, text="You know", activebackground= 'DarkOrange1', activeforeground = 'DeepSkyBlue1', bg = 'hot pink', fg = 'lemon chiffon', command=youknows).place(x= 425, y = 25)

    ok = 0
    def oks():
    global ok
    ok = ok + 1
    oklabel.configure(text = ok)

    oklabel = tk.Label(window, text = ok, bg = 'honeydew2', fg = 'blue2')
    oklabel.place(x = 595, y = 1 )

    okbutton = tk.Button(window, text="Ok", activebackground= 'midnight blue', activeforeground = 'SeaGreen2', bg = 'SlateBlue2', fg = 'magenta2', command=oks).place(x= 575, y = 25)

    print(f"um: {(um)}")
    print(f"like: {like}")
    print(f"uh: {uh}")
    print(f"basically: {basically}")
    print(f"ok: {ok}")
    print(f"youknow: {youknow}")


    window.mainloop()

    Continue reading...

Compartilhe esta Página