python 3.x - How do I put more than one label into a frame using tkinter? -


i trying put label underneath label on frame in tkinter either 1 label printing on top of other or seem frame doubled underneath itself. how fix problem?

this code using:

class teachingcontent(tk):      def __init__(self):         super(teachingcontent, self).__init__()         self.nextlabel = none         self.nextlabeltext = stringvar()         self.nextlabeltext.set("next window")          self.tutortitlefont = font.font(family='helvetica', size=16, weight='bold')         self.tutorcontentfont = font.font(family='helvetica', size=14, weight='normal')         self.tutorcodefont = font.font(family='helvetica', size=12, weight='normal')         self.tutorbuttonfont = font.font(family = 'helvetica', size=12, weight='bold')         self.title_height = 40           self.firstprogram_title_frame = ttk.frame()         self.firstprogram_frame = ttk.frame()          def nextbuttonpressed(self):         pass        def prevbuttonpressed(self):         pass       def formsize(self):          self.configure(bg = 'black') # sets colour of gui screen black         self.geometry("650x450+200+200") # sets size of gui         self.title("python tutor")           self.nbutton = button(text = "next", command = self.nextbuttonpressed, bg = 'grey25', activebackground = 'gray19',                               activeforeground = 'dodgerblue1', fg = 'royal blue', width = 8, font = self.tutorbuttonfont).place(x=561,y=418)          self.pbutton = button(text = "previous", command = self.prevbuttonpressed, bg = 'grey25', activebackground = 'gray19',                               activeforeground = 'dodgerblue1', fg = 'royal blue', width = 8, font = self.tutorbuttonfont).place(x=0,y=418)           self.firstprogram_title_frame.configure(height=self.title_height)         self.firstprogram_title_frame['borderwidth'] = 2         self.firstprogram_title_frame.grid(column=0, 0, padx=33,                                     pady=50, sticky=(w, n, e))          self.firstprogram_frame.configure()         self.firstprogram_frame['borderwidth'] = 2         self.firstprogram_frame['relief'] = 'sunken'         self.firstprogram_frame.grid(column=0, row=0, padx=33, pady=50, sticky=(w, n, e))         def firstprogram(self):         self.formsize()         self.firstprogramtitlelabel = label(self.firstprogram_title_frame, text = "a first program", font=self.tutortitlefont)         self.firstprogramtitlelabel.pack()         self.firstprogramlabel = label(self.firstprogram_frame, text = "this program reads in 2 numbers, adds them , prints out result",                                     font = self.tutorcontentfont, wraplength = 500, width = 35, height = 14)          self.firstprogramlabel.grid(column=self.0, row=0, ipadx = 85, pady = 11, padx = 11, sticky=(n))         self.firstprogram = label(self.firstprogram_frame, text = "# program works out result adding 2 numbers\n# rob miles november 2012\n\n# read numbers\                                   \nfirststring = input ('enter first number: ')\nfirstnumber = int(firststring)\                                   \nsecondstring = input ('enter second number: ')\nsecondnumber = int(secondstring)\n\n# work out sum\                                   \nresult = firstnumber + secondnumber\n\n# display result\nprint ('the result is: ', result)",                                     font = self.tutorcodefont, wraplength = 500, width = 35, height = 14, justify = left)          self.firstprogram.grid(column=self.0, row=0, ipadx = 85, pady = 11, padx = 11, sticky=(n))    tc = teachingcontent() tc.firstprogram() 

next time put effort in posting working code here, right?

my traceback log make code running:

  file "tkinterlabel.py", line 68     self.firstprogramlabel.grid(column=self.0, row=0, ipadx = 85, pady = 11, padx = 11, sticky=(n))                                             ^ syntaxerror: invalid syntax    file "tkinterlabel.py", line 75     self.firstprogram.grid(column=self.0, row=0, ipadx = 85, pady = 11, padx = 11, sticky=(n))                                        ^ syntaxerror: invalid syntax    file "tkinterlabel.py", line 50     self.firstprogram_title_frame.grid(column=0, 0, padx=33,                                                         ^ syntaxerror: non-keyword arg after keyword arg  traceback (most recent call last):   file "tkinterlabel.py", line 3, in <module>     class teachingcontent(tk): nameerror: name 'tk' not defined  traceback (most recent call last):   file "tkinterlabel.py", line 79, in <module>     tc = teachingcontent()   file "tkinterlabel.py", line 11, in __init__     self.tutortitlefont = font.font(family='helvetica', size=16, weight='bold') nameerror: name 'font' not defined  traceback (most recent call last):   file "tkinterlabel.py", line 80, in <module>     tc = teachingcontent()   file "tkinterlabel.py", line 19, in __init__     self.firstprogram_title_frame = ttk.frame() nameerror: name 'ttk' not defined 

mistakes you've made:

  • submitted wrong code
  • you messed grid rows , columns
  • you mixed grid , pack layout managers
  • height in label measured in rows not pixels

some of corrections:

self.firstprogram_title_frame.grid(column=0, row=0, padx=33, pady=5, sticky='n') self.firstprogram_frame.grid(column=0, row=1, padx=33, sticky='n') self.firstprogramtitlelabel.grid(column=0, row=0) self.firstprogramlabel = label(self.firstprogram_frame, text = "blabla", font = self.tutorcontentfont, wraplength = 500, width = 35) self.firstprogram.grid(column=0, row=1, sticky='n', ipadx = 85) 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -