Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from tkinter import *
- ACol = 0
- ARow = 0
- cell_w = 60
- cell_h = 30
- class Tabelka():
- def __init__(self, okno,ACol,ARow):
- self.c=Canvas(okno,width=ACol*cell_w,height=ARow*cell_h, bg="white")
- self.c.pack()
- img=PhotoImage(width=ACol*cell_w,height=ARow*cell_h)
- self.c.create_image((ACol*cell_w//2,ARow*cell_h//2),image=img)
- for w in range(0, ARow):
- for k in range(0, ACol):
- self.c.create_rectangle(cell_w*k,cell_h*w,cell_w*(k+1),cell_h*(w+1))
- self.tab = [[None] * ARow for i in range(ACol)]
- def Cell(self, ACol=0, ARow=0, val=None):
- if val is not None:
- self.c.create_rectangle(cell_w*ACol,cell_h*ARow,cell_w*(ACol+1),cell_h*(ARow+1), fill="white")
- self.c.create_text(cell_w*ACol+20,cell_h*ARow+15,text=str(val))
- self.tab[ACol][ARow]=val
- else:
- val = self.tab[ACol][ARow]
- return val
- import random
- def losuj():
- for x in range(0,8):
- for y in range(0,6):
- z=random.randint(0,100)
- t.Cell(x,y,z)
- s.set(t.Cell(0,1))
- okno = Tk()
- okno.geometry("800x600")
- t= Tabelka(okno,8,6)
- b= Button(okno, text="Losuj", command=losuj)
- b.pack()
- s = StringVar()
- lab = Label(okno, textvariable=s)
- lab.pack()
- def parzysta():
- licznik = 0
- for x in range(0,8):
- for y in range(0,6):
- z=random.randint(0,100)
- t.Cell(x,y,z)
- if int(t.Cell(x,y)) %2==0:
- licznik += 1
- s.set(licznik)
- b2= Button(okno, text="Policz ile jest parzystych w całej tabelce", command=parzysta)
- b2.pack()
- def sumuj():
- for x in range(0,8):
- suma = 0
- for y in range(0,6):
- suma += int(t.Cell(x,y))
- t.Cell(x,6,suma)
- b3= Button(okno, text="Oblicz sumę w poszczególnych kolumnach", command=sumuj )
- b3.pack()
- def najwieksza():
- for x in range(0,8):
- maks = 0
- for y in range(0,6):
- if int(t.Cell(x,y))>maks:
- maks = int(t.Cell(x,y))
- t.Cell(x,5,maks)
- b4= Button(okno, text="Wartosc najwieksza", command=najwieksza )
- b4.pack()
- okno.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement