Posted By

maturanti19 on 05/22/19


Tagged

python Tkinter prieskum


Versions (?)

Prieskum


 / Published in: Python
 

Vytvorte program s prieskumom spolupraca s txt a 2 gombiky ukonci hlasovanie

  1. import tkinter
  2. canvas = tkinter.Canvas(height=100, width=600, bg='gainsboro')
  3. canvas.pack()
  4. canvas.create_text(300, 50, text='S T E Š ? A S T N Á/Ý ?', font='Times 42')
  5. s=open('prieskum.txt', 'w')
  6. s.close()
  7.  
  8. def ano():
  9. s=open('prieskum.txt', 'a')
  10. s.write('Y\n')
  11. s.close()
  12.  
  13.  
  14.  
  15. def nie():
  16. s=open('prieskum.txt', 'a')
  17. s.write('N\n')
  18. s.close()
  19.  
  20. def vypis():
  21. ano=open('prieskum.txt', 'r')
  22. r=ano.readline()
  23. x=0
  24. y=0
  25. while r!='':
  26. if 'Y' in r:
  27. x+=1
  28. elif 'N' in r:
  29. y+=1
  30. r=ano.readline()
  31. print('Stastni boli: ', x)
  32. print('Nestastni boli: ', y)
  33. ano.close()
  34. vypis()
  35.  
  36.  
  37. button=tkinter.Button(text='Ukonci hlasovanie', command=vypis)
  38. button.pack()
  39.  
  40. buttonANO=tkinter.Button(text='ANO', command=ano)
  41. buttonANO.pack(side='right')
  42.  
  43.  
  44. buttonNIE=tkinter.Button(text='NIE', command=nie)
  45. buttonNIE.pack(side='left')

Report this snippet  

You need to login to post a comment.