-1

Help with the code, I wanted to make a program that asks what number we will learn the multiplication table for. Immediately the user enters a number, then a new window opens and displays random examples with this number, the user enters the answer to the example, the first time it passes and 2 times it doesn’t, writes that it’s wrong. Help to make sure that everything is displayed correctly and the user can solve examples 10 times, and it is desirable that the inscriptions of correct and incorrect ones are displayed on the screen with their values. Here is the code:

import tkinter as tk

from random import randint, choice

def proverittt(num, rannumm, value,entry, ms):

 try:

     if num * rannum == int(value):

         entry.delete(0, 'end')

         rannumm = randint(1, 9)

         ms.config(text=f'{num} x {rannumm}')

         print('yes')

     else:

         print('no')

 exceptValueError:

     print('Error: invalid value entered')

checks if the user answered the example correctly

def window(number):

 win.destroy()

 win2 = tk.Tk() # create a window

 win2.geometry('300x300+400+100')

 win2.title(f'table on {number}')

 win2.config(background='#EE82EE')

create 2 windows

 canvas = tk.Canvas(win2, width=310, height=310, bg='#EE82EE')

 canvas.pack()

 canvas.create_oval(-10, -10, 90, 90, fill='#BA55D3', width=0)

 canvas.create_oval(60, -5, 120, 60, fill='#9370DB', width=0)

 canvas.create_oval(35, -8, 85, 50, fill='#4B0082', width=0)

 canvas.create_oval(100, -14, 190, 80, fill='#9932CC', width=0)

 canvas.create_oval(180, -13, 310, 60, fill='#9932CC', width=0)

 canvas.create_oval(160, -7, 260, 90, fill='#4B0082', width=0)

beauty mugs

 counttrue = 0 # count of correct answers

 countfalse = 0 # count of incorrect answers

 prav = tk.Label(win2, text='correct: ', bg='#FF00FF', font=('Arial', 8, 'bold'))

 prav.place(x=10, y=100)

 prav = tk.Label(win2, text='invalid: ', bg='#FF00FF', font=('Arial', 8, 'bold'))

 prav.place(x=10, y=125)

 # here should appear how many correct answers and how many are not

 tk.Label(win2, text=' ', bg='#FF00FF', font=('Arial', 8, 'bold'), padx=17, pady=7).place(x=130, y=110)

 tk.Label(win2, text=' ', bg='#4B0082', font=('Arial', 8, 'bold'), padx=12, pady=4).place(x=135, y=114)

 # pattern behind example

 popitek = 0 # number of attempts

 # loop until retries are less than 10

 while popitek<10:

     rannum = randint(1,9) # random number for example

     ms = tk.Label(win2, text=f'{number} x {rannum}', bg='#BA55D3', font=('Arial', 8, 'bold')) # output example

     ms.place(x=140, y=117)

     entry = tk.Entry(win2) # here the user writes the answer to the example

     entry.place(x=92, y=150)

     btn = tk.Button(win2, text='verify', command=lambda: proverittt(int(number), rannum, entry.get(), entry, ms))

     btn.place(x=120, y=178) # check example button, pass the number that the user chose at the very beginning, a random number, and what the user entered

     popitek+=1

def proverka():

 kr = inform1.get()

 if kr and kr.isdigit():

     window(cr)

 else:

     tk.Label(win, text='You didn't fill in the field', bg='#9932CC').place(x=90, y=180)

check if there are numbers in the string

win = tk.Tk() # create a window

win.geometry('300x300+700+100')

win.title('multiplication table')

win.config(background='#EE82EE')

win.resizable(False, False)

canvas = tk.Canvas(win, width=310,height=310, bg='#EE82EE')

canvas.pack()

canvas.create_oval(-10,-10,90,90, fill='#BA55D3', width=0)

canvas.create_oval(60,-5,120,60, fill='#9370DB', width=0)

canvas.create_oval(35,-8,85,50, fill='#4B0082', width=0)

canvas.create_oval(100,-14,190,80, fill='#9932CC', width=0)

canvas.create_oval(180,-13,310,60, fill='#9932CC', width=0)

canvas.create_oval(160,-7,260,90, fill='#4B0082', width=0)

circles for beauty

tk.Label(win, text='what number will we learn the multiplication table from?', bg='#EE82EE', font=('Arial',8, 'bold')).place(x=10, y=90)

inform1 = tk.Entry(win)

inform1.place(x=90,y=120)

knopka = tk.Button(win, text='start', command=proverka)

knopka.place(x=130,y=150)

win.mainloop()

I've been trying for a few hours but it didn't work, please help

1 Answers1

0

There is a lot going on here, and a lot that is not going on.

  • print() only works in the terminal. It does not place anything into a GUI. You need functions to set the result values into the labels or entry boxes and then connect the labels or entry boxes to those functions.

  • You have buttons in your popitek function; do you want those to be part of the function or are they supposed to be independent of the function?

From there, go piece by piece through your code, testing each part to see when things stop working and then find or ask specific questions here.

  • if it's not difficult for you, could you write a program that displays different examples and the user has to answer them in the Tkinter library. I will see how your code works and thanks to it I can make my own – Kripersi Jul 25 '23 at 12:23
  • 1
    @Kripersi you are asking for too many things in one question. You also did not answer my question. So no, I cannot. – Tyler Bishop Jul 25 '23 at 17:44