0

I am new to Tkinter, but is seems intuitive enough. however, I am scratching my head attempting to place 3 labels in specific frames. Upon running the code, each of the labels seem to display outside of the frame and in the main window.

#Updated Version

#Library
from tkinter import *
import os


#Initialise main window
main_window = Tk()
main_window.title("Mathify For Kids")

#Create Main window size
main_window.geometry("500x500")

#Top frame
top_frame = Frame(master = main_window,width=500,height=100,bg="grey",pady=2).grid(row=0,column=0)
app_title = Label(top_frame,text="ARITHMETIC HELPER FOR KIDS",bg="brown",fg="white").grid(row=0,column=0)

#Middle frame
middle_frame = LabelFrame(master = main_window ,width=500,height=300,bg="light grey",pady=2).grid(row=1,column=0)

#Labels for data entry
label_number_one = Label(middle_frame,text="Number One:")
label_number_one.grid(row=0)

label_number_two = Label(middle_frame,text="Number Two:")
label_number_two.grid(row=1)

label_number_three = Label(middle_frame,text="Number Three:")
label_number_three.grid(row=2)



#Bottom frame
bottom_frame = Frame(main_window,width=500,height=100,bg="grey",pady=2).grid(row=3,column=0)

ufookoro
  • 337
  • 1
  • 4
  • 12
  • 1
    You are not using `grid()` on those labels. – Delrius Euphoria Jun 13 '21 at 11:11
  • I do apologise, whilst I was testing, I was adding and removing the grid code. So the grid command I was using was Label(middle_frame,text="Number_one).grid(row=0,column=0) – ufookoro Jun 13 '21 at 11:15
  • 1
    You shouldn't use `middle_frame = Frame(...).grid(...)`. Instead split it in 2 lines: `middle_frame = Frame(...)` and `middle_frame.grid(...)`. Same goes for your other frames – TheLizzard Jun 13 '21 at 11:19
  • Update the code with new code, it is probably `None`. – Delrius Euphoria Jun 13 '21 at 11:19
  • @TheLizzard It is probably the duplicate itself but an error wont show up because `master=None` is valid – Delrius Euphoria Jun 13 '21 at 11:21
  • @CoolCloud I don't see any errors and if `master` is `None`, `tkinter` will place those widgets inside the main `Tk()` window. That seems like the behaviour OP is trying to avoid. Passing in the correct `master` should solve the problem. Am I missing something? – TheLizzard Jun 13 '21 at 11:24
  • Thanks TheLizzard. I will break up the grid reference and let you know. Kind Regards – ufookoro Jun 13 '21 at 11:32
  • @CoolCloud. Thanks, Will give this a go and update. Thanks – ufookoro Jun 13 '21 at 11:34
  • 1
    @TheLizzard That is the correct answer, I meant the question linked is related to an error but here there will not be any error – Delrius Euphoria Jun 13 '21 at 11:40
  • @CoolCloud Oh, I was saying that it was the same problem :D. The problem of calling `variable = Widget(...).grid(...)`. Next time I will make sure I point it out, thanks – TheLizzard Jun 13 '21 at 11:42
  • I have updated my code to reflect the suggestions, but does not seem o have made any difference.. The labels continue to appear outside the frame – ufookoro Jun 13 '21 at 11:54
  • @ufookoro You need to split `top_frame = Frame(...).grid(...)` in 2 lines as well. Same goes for your other frames. – TheLizzard Jun 13 '21 at 11:59
  • Hello @TheLizzard, I have just noticed this. and the labels have just begun to insert themselves in the correct frame, though some formatting is needed which I should be able to sort out. Thanks all, I will mark question as resolved. – ufookoro Jun 13 '21 at 12:05
  • @TheLizzard for the life of me, I cannot find the the Tag, Tick where I can indicate that this question has been answered – ufookoro Jun 13 '21 at 12:16
  • 2
    @ufookoro The tick thing is only available only when someone answers the question. As this question is very similar to the other one that I linked, I will get killed by the community if I write an answer :D. So just forget about the question or you can delete the question if you want to. It's fine, I wanted to help you and I did. That is what counts – TheLizzard Jun 13 '21 at 12:49

0 Answers0