वेरिएबल AnswerQuestionPageText2Variable अपडेट क्यों नहीं होगा? मैंने mainloop, configure, और set की कोशिश की है लेकिन यह वही रहता है। मैं चाहता हूं कि यह हर बार MainMenuButton1Command (प्रारंभ बटन) दबाए जाने पर सूची से एक यादृच्छिक प्रश्न चुनें TrueQuestions

#imports
from tkinter import *
from tkinter.font import *
import random
#lists
TrueQuestions = [
    'true question 1',
    'true question 2',
    'true question 3',]
current_question = random.choice(TrueQuestions)
#command defines
def MainMenuButton1Command():
    MainMenu.withdraw()
    AnswerQuestionPage.deiconify()
    #attempting to update AnswerQuestionPageText2Variable when start button pressed
    current_question = random.choice(TrueQuestions)
    AnswerQuestionPageText2Variable.set(current_question)
def MainMenuButton5Command():
    quit()
def AnswerQuestionPageButton1Command():
    AnswerQuestionPage.withdraw()
    MainMenu.deiconify()
#MainMenu
MainMenu = Tk()
MainMenu.attributes("-fullscreen", True)
MainMenu.title("IQ extreme Main Menu")
MainMenu.configure(bg="blue")
BigFont = Font(family="Tahoma",size=48,weight="bold")
SmallFont = Font(family="Tahoma",size=24)
TinyFont = Font(family="Tahoma",size=18)
MainMenuButton1 = Button(MainMenu,bg="white",fg="black",font=TinyFont,text="Start",width=20,command=MainMenuButton1Command)
MainMenuButton1.place(x=525,y=400)
MainMenuButton5 = Button(MainMenu,bg="red",fg="black",font=TinyFont,text="Quit",width=5,command=MainMenuButton5Command)
MainMenuButton5.place(x=1200,y=950)
#AnswerQuestionPage
AnswerQuestionPage = Tk()
AnswerQuestionPage.withdraw()
BigFont = Font(AnswerQuestionPage,family="Tahoma",size=48,weight="bold")
SmallFont = Font(AnswerQuestionPage,family="Tahoma",size=24)
TinyFont = Font(AnswerQuestionPage,family="Tahoma",size=18)
AnswerQuestionPage.attributes("-fullscreen", True)
AnswerQuestionPage.title("IQ extreme")
AnswerQuestionPage.configure(bg="blue")
AnswerQuestionPageText2Variable = StringVar()
AnswerQuestionPageText2Variable.set(current_question)
AnswerQuestionPageText2 = Label(AnswerQuestionPage,bg="blue",fg="black",font=BigFont,text="Question: "+str(current_question))
AnswerQuestionPageText2.place(x=350,y=50)
AnswerQuestionPageButton1 = Button(AnswerQuestionPage,bg="white",fg="black",font=TinyFont,text="Home",width=5,command=AnswerQuestionPageButton1Command)
AnswerQuestionPageButton1.place(x=1205,y=5)

कोई भी मदद बहुत अच्छी रहेगी। धन्यवाद।

1
Samuel May 11 फरवरी 2021, 12:45

2 जवाब

सबसे बढ़िया उत्तर

यहां आप टेक्स्टवेरिएबल के लिए वर्किंग कोड देख सकते हैं:

from tkinter import *
from tkinter.font import *
import random
# lists
TrueQuestions = [
    'true question 1',
    'true question 2',
    'true question 3', ]
current_question = random.choice(TrueQuestions)
AnswerQuestionPage = Tk()
BigFont = Font(AnswerQuestionPage, family="Tahoma", size=48, weight="bold")
SmallFont = Font(AnswerQuestionPage, family="Tahoma", size=24)
TinyFont = Font(AnswerQuestionPage, family="Tahoma", size=18)
AnswerQuestionPage.attributes("-fullscreen", True)
AnswerQuestionPage.title("IQ extreme")
AnswerQuestionPage.configure(bg="blue")
AnswerQuestionPageText2Variable = StringVar()
AnswerQuestionPageText2Variable.set(current_question)
AnswerQuestionPageText2 = Label(AnswerQuestionPage,
                                bg="blue",
                                fg="black",
                                font=BigFont,
                                textvariable=AnswerQuestionPageText2Variable)
AnswerQuestionPageText2.place(x=350, y=50)
AnswerQuestionPage.mainloop()
2
hussic 11 फरवरी 2021, 19:15

आपको AnswerQuestionPageText2 लेबल को AnswerQuestionPageText2Variable के साथ उपयोग करने के लिए कहना होगा: Label(textvariable=AnswerQuestionPageText2Variable, ...)

3
hussic 11 फरवरी 2021, 17:11