Auslosung und Progressbar
This commit is contained in:
		
							
								
								
									
										18
									
								
								auslosung.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								auslosung.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
from random import shuffle
 | 
			
		||||
 | 
			
		||||
def print_auslosung(title, studdict):
 | 
			
		||||
    studentslist = list(range(len(studdict)))
 | 
			
		||||
    shuffle(studentslist)
 | 
			
		||||
    print("== {} ==".format(title))
 | 
			
		||||
    i = 1
 | 
			
		||||
    for num in studentslist:
 | 
			
		||||
        print("{} - {}".format(i, studdict[num+1]))
 | 
			
		||||
        i += 1
 | 
			
		||||
    print("---")
 | 
			
		||||
    return True
 | 
			
		||||
        
 | 
			
		||||
studentsdict1 = {1: "Simon", 2: "Maximilian", 3: "Hannah", 4: "Laura", 5: "Clara"}
 | 
			
		||||
studentsdict2 = {1: "Vanessa", 2: "Pascal", 3: "Oliver"}
 | 
			
		||||
 | 
			
		||||
print_auslosung("17.12.2021", studentsdict1)
 | 
			
		||||
print_auslosung("21.12.2021", studentsdict2)
 | 
			
		||||
							
								
								
									
										32
									
								
								tk_first_steps/events.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								tk_first_steps/events.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
import tkinter
 | 
			
		||||
from tkinter import *
 | 
			
		||||
 | 
			
		||||
ws = Tk(  )
 | 
			
		||||
ws.geometry("200x200")
 | 
			
		||||
display='Press Any Button, or Press  Key'
 | 
			
		||||
Lab= Label(ws, text=display, width=len(display))
 | 
			
		||||
Lab.pack(pady=40)
 | 
			
		||||
 | 
			
		||||
def key(eve):
 | 
			
		||||
    if eve.char==eve.keysym:
 | 
			
		||||
        message ='Normal Key %r' % eve.char
 | 
			
		||||
    elif len(eve.char)==1:
 | 
			
		||||
        message ='Punctuation Key %r (%r)' % (eve.keysym, eve.char)
 | 
			
		||||
    else:
 | 
			
		||||
        message ='Special Key %r' % eve.keysym
 | 
			
		||||
    Lab.config(text=message)
 | 
			
		||||
Lab.bind_all('<Key>', key)
 | 
			
		||||
 | 
			
		||||
def do_mouse(eventname):
 | 
			
		||||
    def mouse_binding(event):
 | 
			
		||||
        message = 'Mouse event %s' % eventname
 | 
			
		||||
        Lab.config(text=message)
 | 
			
		||||
    Lab.bind_all('<%s>'%eventname, mouse_binding)
 | 
			
		||||
 | 
			
		||||
for i in range(1,4):
 | 
			
		||||
    do_mouse('Button-%s'%i)
 | 
			
		||||
    do_mouse('ButtonRelease-%s'%i)
 | 
			
		||||
    do_mouse('Double-Button-%s'%i)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ws.mainloop()
 | 
			
		||||
							
								
								
									
										71
									
								
								tk_progress/my_progress.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								tk_progress/my_progress.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
import tkinter as tk
 | 
			
		||||
import tkinter.ttk as ttk
 | 
			
		||||
 | 
			
		||||
class Controller(object):
 | 
			
		||||
    def __init__(self, app):
 | 
			
		||||
        self.app = app
 | 
			
		||||
        self.count = 0
 | 
			
		||||
        self.running = False
 | 
			
		||||
        self.interrupt = False
 | 
			
		||||
 | 
			
		||||
    def run_process(self):
 | 
			
		||||
        steps = 42
 | 
			
		||||
        delta = 100 / steps
 | 
			
		||||
 | 
			
		||||
        print("run {}".format(self.count))
 | 
			
		||||
        self.set_running()
 | 
			
		||||
 | 
			
		||||
        if self.count == steps or self.interrupt:
 | 
			
		||||
            print(self.count)
 | 
			
		||||
            self.running = False
 | 
			
		||||
            self.finish()
 | 
			
		||||
            return 0
 | 
			
		||||
        else:
 | 
			
		||||
            self.count += 1
 | 
			
		||||
            self.app.after(1, lambda : self.app.p.step(delta))
 | 
			
		||||
            self.app.after(50, self.run_process)
 | 
			
		||||
            return 1
 | 
			
		||||
 | 
			
		||||
    def set_interrupt(self):
 | 
			
		||||
        self.interrupt = True
 | 
			
		||||
        self.app.b.configure(text="Reset", command=self.set_reset)
 | 
			
		||||
 | 
			
		||||
    def set_running(self):
 | 
			
		||||
        if not self.interrupt:
 | 
			
		||||
            self.running = True
 | 
			
		||||
            self.app.b.configure(text="Abort", command=self.set_interrupt)
 | 
			
		||||
 | 
			
		||||
    def set_reset(self):
 | 
			
		||||
        self.count = 0
 | 
			
		||||
        self.interrupt=False
 | 
			
		||||
        self.app.pbar_var.set(0)
 | 
			
		||||
        self.app.b.configure(text="Start", command=self.run_process)
 | 
			
		||||
 | 
			
		||||
    def finish(self):
 | 
			
		||||
        print("finished.")
 | 
			
		||||
        self.app.b.configure(text="Restart", command=self.set_reset)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Application(tk.Tk):
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        super().__init__()
 | 
			
		||||
        self.con = Controller(self)
 | 
			
		||||
        self.create_control_variables()
 | 
			
		||||
        self.create_widgets()
 | 
			
		||||
 | 
			
		||||
    def create_control_variables(self):
 | 
			
		||||
        self.pbar_var = tk.IntVar()
 | 
			
		||||
 | 
			
		||||
    def create_widgets(self):
 | 
			
		||||
        self.p = ttk.Progressbar(master=self, length="200", maximum=100, mode="determinate", variable=self.pbar_var)
 | 
			
		||||
        self.p.grid(row=0, column=0)
 | 
			
		||||
 | 
			
		||||
        self.b = ttk.Button(master=self, text="Start", command=self.con.run_process)
 | 
			
		||||
        self.b.grid(row=1, column=0)
 | 
			
		||||
 | 
			
		||||
# --------------------------
 | 
			
		||||
# Execution
 | 
			
		||||
# --------------------------
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    app = Application()
 | 
			
		||||
    app.mainloop()
 | 
			
		||||
		Reference in New Issue
	
	Block a user