Python Forum
[Tkinter] using different frame for some widgets
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] using different frame for some widgets
#1
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.
Reply
#2
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()
rwahdan likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 5,859 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 6,735 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 3,923 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020