Python Forum
[Tkinter] using different frame for some widgets - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] using different frame for some widgets (/thread-34270.html)



using different frame for some widgets - rwahdan - Jul-13-2021

Hi,

I am trying to have some widgets in main frame and others in another frame:
    available_exams.destroy()
    exam_started = Toplevel(screen)
    #DONT ALLOW CLOSING THE WINDOWS
    exam_started.protocol("WM_DELETE_WINDOW",on_closing)
    #fullscreen no buttons
    exam_started.overrideredirect(1)
    #hide the main screen
    screen.withdraw()

    theframe = Frame(exam_started).grid()

    exam_started.title("Exam Main Screen")
    exam_started.geometry("%dx%d+0+0" % (screen.winfo_screenwidth(),screen.winfo_screenheight()))
    Label(exam_started, text=str(f' Candidate Name: {thefullname}       Exam Name: Math'), font=("Arial", 20)).grid(row=0, column=0)
    Label(exam_started, text=thedate, font=("Arial", 20)).grid(row=1, column=0)
    timer_label = Label(exam_started, text="", font=("Arial",20))
    timer_label.grid(row=2,column=0,sticky=E,padx=85)
    photo1 = PhotoImage(file=thephoto[0])
    myLabel = Label(exam_started,image=photo1)
    myLabel.grid(row=3,column=0, sticky=W, padx=700,pady=150)

    Radiobutton(theframe,text=answer1[0],variable=answers,value=answer1[0],font=("Arial",20),
                    command=lambda: clicked(answers.get())).grid(row=4,column=0,sticky=W)
    Radiobutton(theframe, text=answer2[0], variable=answers, value=answer2[0], font=("Arial", 20),
                command=lambda: clicked(answers.get())).grid(row=5, column=0, sticky=W)
    Radiobutton(theframe, text=answer3[0], variable=answers, value=answer3[0], font=("Arial", 20),
                command=lambda: clicked(answers.get())).grid(row=6, column=0, sticky=W)
    Radiobutton(theframe, text=answer4[0], variable=answers, value=answer4[0], font=("Arial", 20),
                command=lambda: clicked(answers.get())).grid(row=7, column=0, sticky=W)

    Label(theframe,text="").grid(row=8,column=0)
    Button(theframe,text="Previous Question",command=math_previous_question)\
        .grid(row=9,column=1, sticky=W)
    Button(theframe,text="Next Question",command=math_next_question)\
        .grid(row=8,column=1, sticky=W)
exam_started is the window i am in and i have also create a frame called theframe. the output shows the first part which is the exam_started window frame and not showing anything for theframe items. no errors.

Thanks.


RE: using different frame for some widgets - Yoriz - Jul-13-2021

You have called grid on
theframe = Frame(exam_started).grid()
which means theframe will be pointing to None

call grid on a separate line to have a reference to Frame
theframe = Frame(exam_started)
theframe.grid()