检查程序

2024-10-01 19:18:22 发布

您现在位置:Python中文网/ 问答频道 /正文

起初我认为这是一个简单的程序,我可以学到很多。但我被困住了。你知道吗

我怎样才能问完不同的问题。我试过一些我想出的办法,但都不管用。你知道吗

这是第一个,我用一个变量x来重新生成问题。这根本不管用。你知道吗

# Laad de database
cnx = mysql.connector.connect(user='FransSchool', password='RandomPass',host='10.0.0.25', database='Overhoor')
cursor = cnx.cursor()

# Maak een grafische interface
gui = Tk()
gui.resizable(width=FALSE, height=FALSE)

# Verklaringen
def verify():
    overify = antwoord.get()

    if overify == Nederlandsevertaling:
        oentry.delete(0,END)
        x=0
    else:
        oentry.delete(0,END)

x = 0
antwoord = StringVar()
willekeurig = random.randint(0,9)

# Indexeer de database
query = "SELECT FRwoord, NLwoord FROM unite8app1 WHERE id=%s"
cursor.execute(query, (willekeurig,))

while x < 1:
    for (FRwoord, NLwoord) in cursor:
        Fransevertaling = FRwoord
        Nederlandsevertaling = NLwoord
    x+=1

这是第二个给了我一个错误。这一次不起作用并不奇怪。在按下按钮时,它尝试接收新的FR和NLwoord。你知道吗

# Laad de database
cnx = mysql.connector.connect(user='FransSchool', password='RandomPass', host='10.0.0.25', database='Overhoor')
cursor = cnx.cursor()
# Maak een grafische interface
gui = Tk()
gui.resizable(width=FALSE, height=FALSE)

# Verklaringen
def verify():
    overify = antwoord.get()

    if overify == Nederlandsevertaling:
        oentry.delete(0,END)
        willekeurig = random.randint(0,9)
        for (FRwoord, NLwoord) in cursor:
            Fransevertaling = FRwoord
            Nederlandsevertaling = NLwoord

    else:
        oentry.delete(0,END)
        #Save the wrong answer aswell as the right answer to print out at the end

antwoord = StringVar()
willekeurig = random.randint(0,9)

# Indexeer de database
query = "SELECT FRwoord, NLwoord FROM unite8app1 WHERE id=%s"
cursor.execute(query, (willekeurig,))

for (FRwoord, NLwoord) in cursor:
        Fransevertaling = FRwoord
        Nederlandsevertaling = NLwoord

# Uiterlijk van het venster

gui.configure(background="white")
gui.title("Overhoorprogramma - Bryan")

# Grafische objecten
style = ttk.Style()

olabel = ttk.Label(gui,text=Fransevertaling,font=("Times", 18), background="white")
olabel.grid(row=0, column=0,padx=5, pady=5, sticky="W")
oentry = ttk.Entry(gui,textvariable=antwoord, font=("Times", 18))
oentry.grid(row=1, column=0,padx=5, pady=5)
obutton = ttk.Button(gui,text="Suivant", command = verify)
obutton.grid(row=1, column=1,padx=5, pady=5)

目前,它只是清除了按钮按下输入框。我们的目标是,每次输入正确的答案都应该跳过,如果输入错误就必须保存。不管是哪种方式,它都必须提出一个新的问题:一个新单词和一个新单词的意思是什么。你知道吗

理想情况下,我正在寻找一个正确的方向,它背后的机制或一小部分代码。你知道吗


Tags: falsedeguideletecursordatabaseendcnx

热门问题