A
A
anton5412020-10-24 23:06:36
Python
anton541, 2020-10-24 23:06:36

Porting from Tkinter to kivy Python?

Good day! Friends, the fact is that I made the Quiz game using tkinter under Windows. Now, I have a goal to "transfer" the code to the kivy frame and make a program for the Android system.
Code on tkinter (a stripped-down version of the quiz, there will be more questions in the original):

from tkinter import *
from tkinter import messagebox
win = Tk()
win.geometry("500x100")

def q1():
    qu1 = Label(win, text='Привет. Ты готов?) Если да, то введи "Поехали"')
    a1 = Entry()
    bt1 = Button(win, text='Дальше', command=lambda: g1(q2))
    qu1.grid(row=0)
    a1.grid(row=1)
    bt1.grid(row=2)
    def g1(q2):
        if a1.get().lower() == "поехали":
            messagebox.showinfo("Начинаем!", "Отвечай максимально грамотно и четко. Если ответишь неправильно - сброс. Встретимся в конце)")
            qu1.grid_forget()
            q2()
        else :
            messagebox.showerror("Нетушки!", "Поехали введи, шо ты тут пишешь?)")
def q2():
    qu2 = Label(win, text='2+2')
    a2 = Entry()
    bt2 = Button(win, text='Дальше', command=lambda: g2(q3))
    qu2.grid(row=0)
    a2.grid(row=1)
    bt2.grid(row=2)
    def g2(q3):
        if a2.get().lower() == "4" :
            messagebox.showinfo("Да!", "Ну это было слишком легко...")
            qu2.grid_forget()
            q3()
        else :
            messagebox.showerror("Нетушки!", "Неправильно!")
def q3():
    qu3 = Label(win, text='Напиши слово правильно: Р@ЗД@ВАТЬ?')
    a3 = Entry()
    bt3 = Button(win, text='Дальше', command=lambda: g3(q3))
    qu3.grid(row=0)
    a3.grid(row=1)
    bt3.grid(row=2)
    def g3(q3):
        if a3.get().lower() == "раздавать" :
            messagebox.showinfo(":)", "Викторина пройдена!")
        else :
            qu3.grid_forget()
            q2()
            messagebox.showerror("Нетушки!","Неправильно!")
q1()
win.title("Test")
win.mainloop()


The structure of the program is as follows: each question is a separate function in which there is a subfunction for checking the answer (correct - notification of correctness, the next question (function), incorrect - notification of an error, return to the first question (second function in a row)). Everything is pretty simple. At the start, function 1 is called, the button checks for the subfunction, if the condition is met, the transition to function 2, and so on until the last question.

I'm interested in exactly: how can I transfer such commands as win = Tk() , qu1 = Label , a1 = Entry , bt1 = Button , a1.get() , messagebox.showinfo , messagebox.showerror ... and other commands specifically for Tkinter to Kivy (I ask you to write analogues for me)

I do not ask you to write the program code for me, I only ask you to explain to me exactly how to replace the whole thing without violating the structure of the program execution (but if someone writes the finished code and gives explanations for the actions, then it will be generally gorgeous and there is no limit my luck). I tried to study the information on my own, but to no avail. Nothing happens, all sorts of errors fly out, crashes, etc. I can’t even give an example of the code, because I’m sure that it is clumsy and will not clarify the situation in any way.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question