Kuis

Kembangkan Game Matematika menggunakan TkInter Python

Dipublikasikan pada : 7 Februari 2021.

from tkinter import *

 

def keterangan(r,c):

global angka

angka = prima(periksa[r][c])

print(periksa[r][c])

if angka:

kotak[r][c].configure(bg=’green’,fg=’red’)

else:

kotak[r][c].configure(bg=’red’,fg=’green’)

 

 

def prima(coba):

global g

g = coba-1

if coba==2:

return True

elif coba>2:

for e in range(2,coba):

f = coba % e

if f !=0 and e==g:

return True

break

if f==0 and e!=g:

return False

break

 

root = Tk()

kotak = [[0]*10 for a in range(10)]

periksa = [[0]*10 for d in range(10)]

nilai = [b for b in range(1,101)]

angka = False

c = -1

g = 0

for i in range(10):

for j in range(10):

c = c+1

kotak[i][j]=Button(text=nilai[c],font=(‘Verdana’,10),width=5,bg=’grey’, command=lambda r=i,c=j:keterangan(r,c))

kotak[i][j].grid(row=i,column=j)

periksa[i][j]=nilai[c]

mainloop()