I am trying to make a small flash card program for my kids. Here is what I have come up with so far, I was hoping if I reassigned the variables in the button function it would randomly pull a new list item. But that does not seem to be the case. I know my code is not he prettiest, I’ve been teaching myself how to code for about 3 weeks now, so if there is anything else anyone can recommend to help improve this I would appreciate it.
import tkinter as tk
import random
window = tk.Tk()
window.geometry("300x600")
window.title("Flash Card Master")
x = [1, 2, 3, 4, 5, 6, 7, 8, 9 ];
y = [1, 2, 3, 4, 5, 6, 7, 8, 9 ];
a = ''
plus = '+'
rx = random.choice(x)
ry = random.choice(y)
top = tk.Label(text = rx, font="Georgia 100 bold")
operator = tk.Label(text = plus, font="Georgia 100 bold")
bottom = tk.Label(text = ry, font="Georgia 100 bold")
slash = tk.Label(text = ' ____________________', font="Georgia 10 bold")
answere = tk.Label(text = '', font="Georgia 100 bold")
top.grid(row=0, column=1)
operator.grid(row=1, column=0)
bottom.grid(row=1, column=1)
slash.grid(row=2, column=0, columnspan=3)
answere.grid(row=3, column=1)
def press():
answere.config(text = rx + ry)
b1 = tk.Button(text = "Click ME!", command = press)
b1.grid()
def press():
answere.config(text = a)
rx = random.choice(x)
ry = random.choice(y)
top = tk.Label(text = rx, font="Georgia 100 bold")
operator = tk.Label(text = plus, font="Georgia 100 bold")
bottom = tk.Label(text = ry, font="Georgia 100 bold")
b1 = tk.Button(text = "Next", command = press)
b1.grid()
window.mainloop()
Aucun commentaire:
Enregistrer un commentaire