Advertisement
Guest User

20.03.2019 python

a guest
Mar 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3.  
  4. from tkinter import *
  5. ACol = 0
  6. ARow = 0
  7. cell_w = 60
  8. cell_h = 30
  9.  
  10. class Tabelka():
  11. def __init__(self, okno,ACol,ARow):
  12. self.c=Canvas(okno,width=ACol*cell_w,height=ARow*cell_h, bg="white")
  13. self.c.pack()
  14. img=PhotoImage(width=ACol*cell_w,height=ARow*cell_h)
  15. self.c.create_image((ACol*cell_w//2,ARow*cell_h//2),image=img)
  16.  
  17. for w in range(0, ARow):
  18. for k in range(0, ACol):
  19. self.c.create_rectangle(cell_w*k,cell_h*w,cell_w*(k+1),cell_h*(w+1))
  20. self.tab = [[None] * ARow for i in range(ACol)]
  21.  
  22. def Cell(self, ACol=0, ARow=0, val=None):
  23. if val is not None:
  24. self.c.create_rectangle(cell_w*ACol,cell_h*ARow,cell_w*(ACol+1),cell_h*(ARow+1), fill="white")
  25. self.c.create_text(cell_w*ACol+20,cell_h*ARow+15,text=str(val))
  26. self.tab[ACol][ARow]=val
  27. else:
  28. val = self.tab[ACol][ARow]
  29. return val
  30. import random
  31.  
  32. def losuj():
  33. for x in range(0,8):
  34. for y in range(0,6):
  35. z=random.randint(0,100)
  36. t.Cell(x,y,z)
  37. s.set(t.Cell(0,1))
  38.  
  39. okno = Tk()
  40. okno.geometry("800x600")
  41.  
  42. t= Tabelka(okno,8,6)
  43.  
  44. b= Button(okno, text="Losuj", command=losuj)
  45. b.pack()
  46.  
  47.  
  48. s = StringVar()
  49. lab = Label(okno, textvariable=s)
  50. lab.pack()
  51.  
  52. def parzysta():
  53. licznik = 0
  54. for x in range(0,8):
  55. for y in range(0,6):
  56. z=random.randint(0,100)
  57. t.Cell(x,y,z)
  58. if int(t.Cell(x,y)) %2==0:
  59. licznik += 1
  60. s.set(licznik)
  61.  
  62. b2= Button(okno, text="Policz ile jest parzystych w całej tabelce", command=parzysta)
  63. b2.pack()
  64.  
  65.  
  66. def sumuj():
  67.  
  68. for x in range(0,8):
  69. suma = 0
  70. for y in range(0,6):
  71. suma += int(t.Cell(x,y))
  72. t.Cell(x,6,suma)
  73.  
  74.  
  75.  
  76.  
  77. b3= Button(okno, text="Oblicz sumę w poszczególnych kolumnach", command=sumuj )
  78. b3.pack()
  79.  
  80.  
  81.  
  82.  
  83.  
  84. def najwieksza():
  85. for x in range(0,8):
  86. maks = 0
  87. for y in range(0,6):
  88. if int(t.Cell(x,y))>maks:
  89. maks = int(t.Cell(x,y))
  90. t.Cell(x,5,maks)
  91.  
  92. b4= Button(okno, text="Wartosc najwieksza", command=najwieksza )
  93. b4.pack()
  94.  
  95.  
  96. okno.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement