Python Forum
Show the result of every count
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Show the result of every count
#4
One way

#! /usr/bin/env python3

import tkinter as tk
import sys

class Window:
    def __init__(self, parent):
        self.counter = 0
        container = tk.Frame(parent)
        container.grid(column=0, row=0, sticky='new')

        self.label = tk.Label(container)
        self.label['text'] = 'Counter: 0'
        self.label.grid(column=0, row=0, sticky='new')

        btnframe = tk.Frame(parent)
        btnframe.grid(column=0, row=1, sticky='new')
        for i in range(3):
            btnframe.grid_columnconfigure(i, weight=3, uniform='btns')

        btn1 = tk.Button(btnframe, text='Up', command=self.up)
        btn1.grid(column=0, row=1, sticky='new')

        btn2 = tk.Button(btnframe, text='Down', command=self.down)
        btn2.grid(column=1, row=1, sticky='new')

        btn3 = tk.Button(btnframe, text='Exit', command=sys.exit)
        btn3.grid(column=2, row=1, sticky='new')

    def up(self):
        self.counter += 1
        self.label['text'] = f'Counter: {self.counter}'

    def down(self):
        if self.counter < 1:
            self.counter = 0
        else:
            self.counter -= 1
        self.label['text'] = f'Counter: {self.counter}'

def main():
    root = tk.Tk()
    root['padx'] = 5
    root['pady'] = 3
    Window(root)
    root.mainloop()

main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Show the result of every count - by George87 - Dec-28-2021, 11:42 AM
RE: Show the result of every count - by menator01 - Dec-28-2021, 01:48 PM
RE: Show the result of every count - by George87 - Dec-28-2021, 02:17 PM
RE: Show the result of every count - by menator01 - Dec-28-2021, 03:36 PM
RE: Show the result of every count - by menator01 - Dec-28-2021, 04:00 PM
RE: Show the result of every count - by George87 - Dec-28-2021, 05:16 PM
RE: Show the result of every count - by deanhystad - Dec-28-2021, 05:33 PM
RE: Show the result of every count - by menator01 - Dec-28-2021, 06:04 PM
RE: Show the result of every count - by deanhystad - Dec-28-2021, 08:58 PM
RE: Show the result of every count - by menator01 - Dec-28-2021, 09:04 PM
RE: Show the result of every count - by deanhystad - Dec-28-2021, 10:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] How to get the result of a ping to show in tkinter? jacklee26 6 7,909 Feb-10-2023, 01:12 PM
Last Post: NebularNerd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020