Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.26 KB | None | 0 0
  1. from tkinter import *
  2. from random import randint
  3.  
  4.  
  5. #Get current selected items from ListBox and choose them randomly for each subject
  6.  
  7. #────Function───────────────────────────────────────────────────────────┐
  8. def btn_click():                                                       #│
  9.     tpl = lb.curselection()                                            #│
  10.     subject_tpl = lb2.curselection()                                   #│
  11.     for i in subject_tpl:                                              #│
  12.         print(f"{lb2.get(i)}: {lb.get(tpl[randint(0, len(tpl)-1)])}\n")#│
  13. #───────────────────────────────────────────────────────────────────────┘
  14.  
  15. #────Lists────────────────────────────────────────────────────────────────────────────────────────────┐
  16. subjects = ['Springs','Tension (Rope)','Newton - Law 1','Newton - Law 2','Newton - Law 3','Friction']#│
  17.                                                                                                      #│
  18. kids = ['Norel', 'Yoav B', 'Ori', 'Jordan']                                                          #│
  19. #─────────────────────────────────────────────────────────────────────────────────────────────────────┘
  20.  
  21.  
  22. #────GUI─────────────────────────────────────────────────────────┐
  23. window = Tk()                                                   #│
  24. lb = Listbox(window, selectmode='multiple', exportselection=0)  #│          
  25. lb.pack(side = LEFT)                                            #│
  26.                                                                 #│
  27. for i in kids:                                                  #│
  28.     lb.insert(END, i)                                           #│
  29.                                                                 #│
  30. lb2 = Listbox(window, selectmode='multiple', exportselection=0) #│
  31. lb2.pack(side = LEFT)                                           #│
  32.                                                                 #│
  33. for i in subjects:                                              #│
  34.     lb2.insert(END, i)                                          #│
  35.                                                                 #│
  36. btn = Button(window, text='Click', command=btn_click)           #│
  37. btn.pack(side = LEFT)                                           #│
  38.                                                                 #│
  39. window.mainloop()                                               #│
  40. #────────────────────────────────────────────────────────────────┘
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement