Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,24 @@
import random, tkMessageBox
from Tkinter import *
window = Tk()
window.geometry("300x50+100+100")
options = { "padx":5, "pady":5}
s=StringVar()
s.set(1)
def increase():
s.set(int(s.get())+1)
def rand():
if tkMessageBox.askyesno("Confirmation", "Reset to random value ?"):
s.set(random.randrange(0,5000))
def update(e):
if not e.char.isdigit():
tkMessageBox.showerror('Error', 'Invalid input !')
return "break"
e = Entry(text=s)
e.grid(column=0, row=0, **options)
e.bind('<Key>', update)
b1 = Button(text="Increase", command=increase, **options )
b1.grid(column=1, row=0, **options)
b2 = Button(text="Random", command=rand, **options)
b2.grid(column=2, row=0, **options)
mainloop()

View file

@ -0,0 +1,29 @@
import random, tkinter.messagebox
from tkinter import *
window = Tk()
window.geometry("330x50+100+100")
options = { "padx":5, "pady":5}
s=StringVar()
s.set(1)
def increase():
s.set(int(s.get())+1)
def rand():
if messagebox.askyesno("Confirmation", "Reset to random value ?"):
s.set(random.randrange(0,5000))
def update(e):
if not e.char.isdigit():
messagebox.showerror('Error', 'Invalid input !')
return "break"
e = Entry(text=s)
e.grid(column=0, row=0, **options)
e.bind('<Key>', update)
b1 = Button(text="Increase", command=increase, **options )
b1.grid(column=1, row=0, **options)
b2 = Button(text="Random", command=rand, **options)
b2.grid(column=2, row=0, **options)
mainloop()

View file

@ -0,0 +1,53 @@
import random
from Tkinter import *
import tkMessageBox
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.counter = 0
self.contents = StringVar()
self.contents.set(str(self.counter))
self.pack(expand=True, fill='both', padx=10, pady=15)
self.create_widgets()
def increment(self, *args):
self.counter += 1
self.update_entry()
def random(self):
if tkMessageBox.askyesno("Confirmation", "Reset to random value ?"):
self.counter = random.randint(0, 5000)
self.update_entry()
def entry_updated(self, event, *args):
if not event.char:
return 'break'
if not event.char.isdigit():
tkMessageBox.showerror('Error', 'Invalid input !')
return 'break'
self.counter = int('%s%s' % (self.contents.get(), event.char))
def update_entry(self):
self.contents.set(str(self.counter))
self.entry['textvariable'] = self.contents
def create_widgets(self):
options = {'expand': True, 'fill': 'x', 'side': 'left', 'padx': 5}
self.entry = Entry(self)
self.entry.bind('<Key>', self.entry_updated)
self.entry.pack(**options)
self.update_entry()
self.increment_button = Button(self, text='Increment', command=self.increment)
self.increment_button.pack(**options)
self.random_button = Button(self, text='Random', command=self.random)
self.random_button.pack(**options)
if __name__ == '__main__':
root = Tk()
try:
app = Application(master=root)
app.master.title("Rosetta code")
app.mainloop()
except KeyboardInterrupt:
root.destroy()