Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from random import randint
- #Get current selected items from ListBox and choose them randomly for each subject
- #────Function───────────────────────────────────────────────────────────┐
- def btn_click(): #│
- tpl = lb.curselection() #│
- subject_tpl = lb2.curselection() #│
- for i in subject_tpl: #│
- print(f"{lb2.get(i)}: {lb.get(tpl[randint(0, len(tpl)-1)])}\n")#│
- #───────────────────────────────────────────────────────────────────────┘
- #────Lists────────────────────────────────────────────────────────────────────────────────────────────┐
- subjects = ['Springs','Tension (Rope)','Newton - Law 1','Newton - Law 2','Newton - Law 3','Friction']#│
- #│
- kids = ['Norel', 'Yoav B', 'Ori', 'Jordan'] #│
- #─────────────────────────────────────────────────────────────────────────────────────────────────────┘
- #────GUI─────────────────────────────────────────────────────────┐
- window = Tk() #│
- lb = Listbox(window, selectmode='multiple', exportselection=0) #│
- lb.pack(side = LEFT) #│
- #│
- for i in kids: #│
- lb.insert(END, i) #│
- #│
- lb2 = Listbox(window, selectmode='multiple', exportselection=0) #│
- lb2.pack(side = LEFT) #│
- #│
- for i in subjects: #│
- lb2.insert(END, i) #│
- #│
- btn = Button(window, text='Click', command=btn_click) #│
- btn.pack(side = LEFT) #│
- #│
- window.mainloop() #│
- #────────────────────────────────────────────────────────────────┘
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement