Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import ttk, messagebox
- class Application:
- def __init__(self, root):
- root.title('counter example')
- mainFrame = ttk.Frame(root, padding = '4 4 4 4')
- mainFrame.grid(column=0, row=0, sticky=(N, W, S, E))
- root.columnconfigure(0, weight=1)
- root.rowconfigure(0, weight=1)
- incrButton = ttk.Button(mainFrame, text = 'Up', command = self.incrButtonClick)
- incrButton.grid(column=0, row=0, padx=2, pady=2, sticky=(N, S))
- decrButton = ttk.Button(mainFrame, text = 'Dn', command = self.decrButtonClick)
- decrButton.grid(column=0, row=1, padx=2, pady=2, sticky=(N, S))
- resetButton = ttk.Button(mainFrame, text = 'Reset', command = self.resetButtonClick)
- resetButton.grid(column=0, row=2, padx=2, pady=2, sticky=(N, S))
- self.countValue = StringVar()
- countEntry = ttk.Entry(mainFrame, width=3, justify = CENTER, font=('Aptos', 28, 'bold'), textvariable=self.countValue)
- countEntry.grid(column=1, row=0, padx=2, pady=2, rowspan=3, sticky=(N, S, E, W))
- self.countValue.set('42')
- def incrButtonClick(self, **args):
- val = int(self.countValue.get())
- if val == 52:
- messagebox.showinfo(title = 'Stop!!!', message='Meh - the number can\'t go any higher!', icon='error')
- else:
- self.countValue.set(str(val + 1))
- def decrButtonClick(self, **args):
- val = int(self.countValue.get())
- if val == 32:
- messagebox.showinfo(title = 'Stop!!!', message='Meh - the number can\'t go any lower!', icon='error')
- else:
- self.countValue.set(str(val - 1))
- def resetButtonClick(self, **args):
- val = int(self.countValue.get())
- if val == 42:
- messagebox.showinfo(title = 'Stop!!!', message="It's already 42 you numpty!", icon='error')
- else:
- self.countValue.set('42')
- def main():
- root = Tk()
- Application(root)
- root.mainloop()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement