Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Menu destroy
#1
Hello fellow python users:

This program produces a menu of green labels and buttons, a menu of red labels and buttons and a purple menu.

When the red menu comes up I would like the green menu to disappear. There is a frame called "theframe". I know you can destroy a menu by destroying the frame. However, I would be destroying it in the Main class but the frame was created in the FirstMenu class. The Super function has been driving me crazy, so I am trying to avoid it for the time being. Can someone point me in the right direction?


import tkinter as tk

root = tk.Tk()

myfont = "helvitica 25"
mybg = "light sky blue"
myheight = 4
mywidth = 60
myheight2 = 2
mywidth2 = 20
myheight3 = 2
mywidth3 = 20
labcol = "spring green"
anscol = "yellow"
otherbutcol = "skyblue"
commandbutcol = "light sky blue"
mypadx = 4
mypady = 4

class Main:
    def __init__(self, root):
        root.title('My Title')
        self.root = root
        root.geometry('1200x1200')
        self.first_menu()

    def first_menu(self):
        self.fstmenu = FirstMenu(self.root)
        self.fstmenu.fstbutton.bind('<Button-1>',self.second_menu)

    def second_menu(self, event):

        self.secmenu = SecondMenu(self.root)
        self.secmenu.secbutton.bind('<Button-1>', self.third_menu)

    def third_menu(self,event):

        self.thirdmenu = ThirdMenu(self.root)


class FirstMenu(Main):
    def __init__(self, root):
        self.theframe = tk.Frame(root)
        self.fstlabel = tk.Label(self.theframe, text="First Label", bg=["springgreen"], font=myfont,
                                 relief="groove")
        self.fstlabel.config(height=myheight, width=mywidth)
        self.fstlabel.pack()
        self.fstbutton = tk.Button(self.theframe, text="Click here to start.", bg=["springgreen"], font=myfont,
                                   relief="groove")
        self.fstbutton.config(height=myheight, width=mywidth)
        self.fstbutton.pack()
        self.theframe.pack()



class SecondMenu(Main):
    def __init__(self, root):

        self.theframe = tk.Frame(root)
        self.seclabel = tk.Label(self.theframe, text="Second Label", bg="red", font=myfont,
                                 relief="groove")
        self.seclabel.config(height=myheight, width=mywidth)
        self.seclabel.pack()
        self.secbutton = tk.Button(self.theframe, text="This is your second click.", bg="red", font=myfont,
                                   relief="groove")
        self.secbutton.config(height=myheight, width=mywidth)
        self.secbutton.pack()
        self.theframe.pack()


class ThirdMenu(Main):
    def __init__(self, root):
        self.theframe = tk.Frame(root)
        self.thirdlabel = tk.Label(self.theframe, text="Third Label", bg="purple", font=myfont,
                                   relief="groove")
        self.thirdlabel.config(height=myheight, width=mywidth)
        self.thirdlabel.pack()
        self.thirdbutton = tk.Button(self.theframe, text="This is your third click.", bg="purple", font=myfont)
        self.thirdbutton.config(height=myheight, width=mywidth)
        self.thirdbutton.pack()
        self.theframe.pack()




if __name__ == "__main__":
    root = tk.Tk()

    main = Main(root)
    root.mainloop()
Reply
#2
There are two attributes, lift and lower. I have used them in the past, and they do work but not for all widgets.
Essentially, you have two widgets of the same size and you will lift, or lower one to the foreground.

I'm rusty on these as I rarely use tkinter any more, but they are well documented in Shipman's reference manual.
If you don't already have a copy, get one here: https://reu.cct.lsu.edu/documents/Python...kinter.pdf
Reply
#3
I don't see where "super" is applicable to your code. Honestly, I don't understand what you are trying to accomplish with the classes. Your "classes" are really just function calls that use a class-like syntax.

Are you trying to map multiple views to one view window, like changing channels on a TV? One way to do this is erase the old widget and draw the new. This can be done using pack or grid to draw the widget and pack_forget or grid_forget to erase the widget. There's probably a way to do this with place too, but I don't know what that is.

In the example below I made a switcher widget that can hold multiple widgets but displays only one widget at a time. Pressing the button moves on to show the next widget. Switching from one widget to the next is done by the next() method.
import tkinter as tk

class Menu(tk.Frame):
    def __init__(self, parent, text, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)
        self.label = tk.Label(self, text=text)
        self.label.pack()
        self.button = tk.Button(self, text="Push Me")
        self.button.pack()
 
class Switcher(tk.Frame):
    def __init__(self, *args, **kvargs):
        super().__init__(*args, **kvargs)
        self.button = tk.Button(self, text='Next', command=self.next)
        self.button.pack(side='right')
        self.index = None
        self.parts = []

    def add(self, part):
        self.parts.append(part)
        if self.index is None:
            self.next()

    def next(self):
        if self.index is None:
            self.index = 0
        else:
            self.parts[self.index].pack_forget()
            self.index = (self.index + 1) % len(self.parts)
        self.parts[self.index].pack(side='left')

root = tk.Tk()
switcher = Switcher(root)
switcher.pack()
switcher.add(tk.Label(switcher, text='Red', fg='green', width=10))
switcher.add(tk.Label(switcher, text='Green', fg='blue', width=10))
switcher.add(tk.Label(switcher, text='Blue', fg='red', width=10))
root.mainloop()
The things you pack can be a frame that contains multiple widgets
Reply
#4
The superclass/subclass relationship means that the subclass has all of the behaviors and attributes of the superclass and provides new attributes and behaviors and/or modifies attributes and behaviors inherited from the superclass. None of your classes have any relationship to each other. Your menu classes definitely don't have a superclass/subclass relationship with Main. Here is an attempt to use superclass/subclass for your code.
import sys
import tkinter as tk
 
class BaseMenu():
    def __init__(self, parent):
        self.frame = tk.Frame(parent)
        self.label = tk.Label(self.frame, text=" ", font="helvitica 25", relief="groove", \
            height=4, width=20)
        self.label.pack()
        self.button = tk.Button(self.frame, text="Click here to start.", font="helvitica 25", \
            relief="groove", height=4, width=20)
        self.button.pack()

    def set_text(self, label, button):
        self.label['text'] = label
        self.button['text'] = button

    def set_bg(self, color):
        self.frame['bg'] = color
        self.label['bg'] = color
        self.button['bg'] = color

class FirstMenu(BaseMenu):
    def __init__(self, parent):
        super().__init__(parent)
        self.set_bg("springgreen")
        self.set_text('First Label', 'Click here to start') 
 
class SecondMenu(BaseMenu):
    def __init__(self, parent):
        super().__init__(parent)
        self.set_bg("red")
        self.set_text('Second Label', 'This is your second click') 
 
class ThirdMenu(BaseMenu):
    def __init__(self, parent):
        super().__init__(parent)
        self.set_bg("purple")
        self.set_text('Third Label', 'This is your third click') 

class Main:
    def __init__(self, parent):
        self.parent = parent
        parent.title('My Title')
        self.first_menu()

    def first_menu(self):
        self.menu = FirstMenu(self.parent)
        self.menu.button.configure(command = self.second_menu)
        self.menu.frame.pack()
 
    def second_menu(self):
        self.menu.frame.pack_forget()
        self.menu = SecondMenu(self.parent)
        self.menu.button.configure(command = self.third_menu)
        self.menu.frame.pack()
 
    def third_menu(self):
        self.menu.frame.pack_forget()
        self.menu = ThirdMenu(self.parent)
        self.menu.button.configure(command = sys.exit)
        self.menu.frame.pack()

root = tk.Tk()
main = Main(root)
root.mainloop()
BaseMenu is a superclass of FirstMenu, SecondMenu and ThirdMenu. Though this is a proper super/subclass relationship it is still a poor design. None of the menu subclasses really do anything. They have no purpose other than set the background color and some labels. They have no identity. This is demonstrated by the fact that the program is shorter and easier to understand if they are removed.
mport sys
import tkinter as tk
 
class BaseMenu():
    def __init__(self, parent):
        self.frame = tk.Frame(parent)
        self.label = tk.Label(self.frame, text=" ", font="helvitica 25", relief="groove", \
            height=4, width=20)
        self.label.pack()
        self.button = tk.Button(self.frame, text="Click here to start.", font="helvitica 25", \
            relief="groove", height=4, width=20)
        self.button.pack()

    def set_text(self, label, button):
        self.label['text'] = label
        self.button['text'] = button

    def set_bg(self, color):
        self.frame['bg'] = color
        self.label['bg'] = color
        self.button['bg'] = color

class Main:
    def __init__(self, parent):
        self.parent = parent
        parent.title('My Title')
        self.first_menu()

    def first_menu(self):
        self.menu = BaseMenu(self.parent)
        self.menu.set_bg("springgreen")
        self.menu.set_text('First Label', 'Click here to start') 
        self.menu.button.configure(command = self.second_menu)
        self.menu.frame.pack()
 
    def second_menu(self):
        self.menu.frame.pack_forget()
        self.menu = BaseMenu(self.parent)
        self.menu.set_bg("red")
        self.menu.set_text('Second Label', 'This is your second click') 
        self.menu.button.configure(command = self.third_menu)
        self.menu.frame.pack()
 
    def third_menu(self):
        self.menu.frame.pack_forget()
        self.menu = BaseMenu(self.parent)
        self.menu.set_bg("purple")
        self.menu.set_text('Third Label', 'This is your third click') 
        self.menu.button.configure(command = sys.exit)
        self.menu.frame.pack()

root = tk.Tk()
main = Main(root)
root.mainloop()
And if I remove the subclasses I see a lot of commonality in the Main menu methods. Toss in a little abstraction and I might even have some classes worthy a docstring.
import sys
import tkinter as tk
 
class Menu(tk.Frame):
    """I am like a message dialog, but I am placed in a form.  I have a label to display the message
    and a button that is connected to a command.
    """
    def __init__(self, parent, bg, message, button_text='Ok'):
        super().__init__(parent, bg=bg)
        self.label = tk.Label(self, text=message, font="helvitica 25", relief="groove", \
            bg=bg, height=4, width=20)
        self.label.pack()
        self.button = tk.Button(self, text=button_text, font="helvitica 25", \
            bg=bg, relief="groove", height=4, width=20)
        self.button.pack()

    def set_command(self, command):
        """Set the command to call when the button is pressed"""
        self.button.configure(command=command)
        return self

class MenuManager(tk.Frame):
    """I play a sequence of menus.  I display the menus one at a time, advancing
    to the next menu when the menu button is pressed.  After all menus are displayed
    I execute my callback function.
    """
    def __init__(self, parent, menus=None):
        super().__init__(parent)
        self.menus = menus
        self.menu = None
        self.index = -1
        self.command = None
    
    def set_menus(self, menus):
        """Set the menu sequence.  A menu sequence is a list of [bg, message, button_text]
        where bg is the background color, message is the label text, and button_text is
        the text for the button"""
        if self.menu:
            self.menu.pack_forget()
            self.menu = None
        self.menus = menus
        self.index = -1
        return self
 
    def set_command(self, command):
        """Set the command called after all menus are displayed"""
        self.command = command
        return self
    
    def next(self):
        """Advance to next menu"""
        if self.menu:
            self.menu.pack_forget()

        self.index += 1
        if self.index < len(self.menus):
            self.menu = Menu(self, *self.menus[self.index]) \
                .set_command(self.next)
            self.menu.pack()
        else:
            if self.menu:
                self.menu.pack_forget()
                self.menu = None
            if self.command:
                self.command()

A = [['green', 'First Label', 'Click here to start'],
     ['red', 'Second Label', 'This is your second click'],
     ['purple', 'Third Label', 'This is your third click']]
 

B = [['orange', 'First Label', 'Click here to start'],
     ['yellow', 'Second Label', 'This is your second click'],
     ['pink', 'Third Label', 'This is your third click']]

def load_menu(manager, menus, command):
    """A function that lets me string menus together"""
    manager.set_menus(menus).set_command(command).next()

root = tk.Tk()
mm = MenuManager(root)
# String together two menu lists, A and B
load_menu(mm, A, lambda:load_menu(mm, B, sys.exit))
mm.pack()
root.mainloop()
Reply
#5
And because I often harp about reusing widgets instead of throwing them away, here's a recycle version of the previous code.
import sys
import tkinter as tk

class Menu(tk.Frame):
    """I am like a message dialog, but I am placed in a form.  I have a label to display the message
    and a button that is connected to a command.
    """
    def __init__(self, parent, message=' ', button_text='Ok', bg=None):
        super().__init__(parent, bg=bg)
        self.label = tk.Label(self, font="helvitica 25", relief="groove", height=4, width=20)
        self.label.pack()
        self.button = tk.Button(self, font="helvitica 25", relief="groove", height=4, width=20)
        self.button.pack()
        self.config(message, button_text, bg)

    def config(self, message, button_text=None, bg=None):
        self.label['text'] = message
        if button_text is not None:
            self.button['text'] = button_text
        if bg is not None:
            self['bg'] = bg
            self.label['bg'] = bg
            self.button['bg'] = bg

    def set_command(self, command):
        """Set the command to call when the button is pressed"""
        self.button.configure(command=command)
        return self

class MenuManager(tk.Frame):
    """I play a sequence of menus.  I display the menus one at a time, advancing
    to the next menu when the menu button is pressed.  After all menus are displayed
    I execute my callback function.
    """
    def __init__(self, parent, menus=None):
        super().__init__(parent)
        self.menus = menus
        self.menu = Menu(self).set_command(self.next)
        self.index = -1
        self.command = None

    def set_menus(self, menus):
        """Set the menu sequence.  A menu sequence is a list of [bg, message, button_text]
        where bg is the background color, message is the label text, and button_text is
        the text for the button"""
        self.menu.pack_forget()
        self.menus = menus
        self.index = -1
        return self

    def set_command(self, command):
        """Set the command called after all menus are displayed"""
        self.command = command
        return self

    def next(self):
        """Advance to next menu"""
        self.index += 1
        if self.index == 0:
            self.menu.pack()
        if self.index < len(self.menus):
            self.menu.config(*self.menus[self.index])
        else:
            self.menu.pack_forget()
            self.index = -1
            if self.command:
                self.command()

A = [['A0', None, 'red'],
     ['A1', None, 'green'],
     ['A2', None, 'blue']]

B = [['B0', None, 'orange'],
     ['B1', None, 'yellow'],
     ['B2', None, 'pink']]

def load_menu(manager, menus, command):
    """A function that lets me string menus together"""
    manager.set_menus(menus).set_command(command).next()

root = tk.Tk()
mm = MenuManager(root)
# String together two menu lists, A and B
load_menu(mm, A, lambda:load_menu(mm, B, sys.exit))
mm.pack()
root.mainloop()
Reply
#6
deanhystad keeps asking what I am trying to accomplish with my code. The code I previously posted was made to make it easier to follow.

Here is the actual code. Go to addition tables, then threes addition tables to get an idea of what I am trying to do.
import tkinter as tk

root = tk.Tk()
# from tkinter import ttk
myfont = "helvitica 25"
mybg = "light sky blue"
myheight = 4
mywidth = 60
myheight2 = 6
mywidth2 = 20
myheight3 = 3
mywidth3 = 20
labcol = "spring green"
anscol = "yellow"
otherbutcol = "light sky blue"
mypadx =2
mypady=2


class Mathtasks:
    # Mathtasks are math activities for young people.
#Choose addition tables threes to test the program

    def __init__(self, root):
        self.root = root
        root.geometry('1200x1200')
        self.opening()

#This is the opening Menu
    def opening(self):
        self.openingframe = tk.Frame(self.root)
        self.openingframe.grid(row=0, column=0)

        self.kalb = tk.Label(self.openingframe, text="MathTasks", bg=labcol, font=myfont, relief="groove")
        self.kalb.config(height=myheight, width=mywidth)
        self.kalb.grid(row=1, column=1, sticky=tk.W)



        self.clickherebn = tk.Button(self.openingframe, text="Click here to start.", bg=otherbutcol, font=myfont,
                                     relief="groove", command=self.mm)
        self.clickherebn.config(height=myheight, width=mywidth)
        self.clickherebn.grid(row=3, column=1, sticky=tk.W)

        self.quitbn = tk.Button(self.openingframe, text="Quit", font=myfont, bg="red", relief="groove",
                                command=self.openingframe.quit)
        self.quitbn.config(height=myheight, width=mywidth)
        self.quitbn.grid(row=4, column=1, sticky=tk.W)




    #This is the Main Menu
    def mm(self):
        self.openingframe.destroy()

        self.mmframe = tk.Frame(root)
        self.mmframe.grid(row=0, column=0)
        self.menu = tk.Menu(self.mmframe)

        # Addition Tables
        self.add = tk.Menu(self.menu)
        self.menu.add_cascade(label="Addition Tables", menu=self.add)
        self.add.add_command(label="ones addition table", command=lambda:[self.tbles("a", 1)])
        self.add.add_command(label="twos addition table", command=lambda:[self.tbles("a", 2)])
        self.add.add_command(label="threes addition table", command=lambda:[self.tbles("a", 3)])
        self.add.add_separator()
        self.add.add_command(label="fours addition table", command=lambda:[self.tbles("a", 4)])
        self.add.add_command(label="fives addition table", command=lambda:[self.tbles("a", 5)])
        self.add.add_command(label="sixes  addition tables", command=lambda:[self.tbles("a", 6)])
        self.add.add_separator()
        self.add.add_command(label="sevens addition table", command=lambda:[self.tbles("a", 7)])
        self.add.add_command(label="eights addition table", command=lambda:[self.tbles("a", 8)])
        self.add.add_command(label="nines addition table", command=lambda:[self.tbles("a", 9)])
        self.add.add_separator()
        self.add.add_command(label="tens addition table", command=lambda:[self.tbles(a, 10)])
        self.add.add_command(label="elevens addition table", command=lambda:[self.tbles(a, 11)])
        self.add.add_command(label="twelves addition table", command=lambda:[self.tbles(a, 12)])


        # Subtraction Tables
        self.sub = tk.Menu(self.menu)
        self.menu.add_cascade(label="Subtraction Tables", menu=self.sub)
        self.sub.add_command(label="ones subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_command(label="twos subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_command(label="threes subtraction table",command=lambda:[self.tbles("s", 1)])
        self.sub.add_separator()
        self.sub.add_command(label="fours subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_command(label="fives subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_command(label="sixes subtraction tables", command=lambda:[self.tbles("s", 1)])
        self.sub.add_separator()
        self.sub.add_command(label="sevens subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_command(label="eights subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_command(label="nines subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_separator()
        self.sub.add_command(label="tens subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_command(label="elevens subtraction table", command=lambda:[self.tbles("s", 1)])
        self.sub.add_command(label="twelves subtraction table", command=lambda:[self.tbles("s", 1)])


        # Multiplication Tables
        self.multi = tk.Menu(self.menu)
        self.menu.add_cascade(label="Multiplication Tables", menu=self.multi)
        self.multi.add_command(label="ones multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_command(label="twos multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_command(label="threes multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_separator()
        self.multi.add_command(label="fours multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_command(label="fives multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_command(label="sixes  multiplication tables", command=lambda:[self.tbles("m", 1)])
        self.multi.add_separator()
        self.multi.add_command(label="sevens multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_command(label="eights multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_command(label="nines multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_separator()
        self.multi.add_command(label="tens multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_command(label="elevens multiplication table", command=lambda:[self.tbles("m", 1)])
        self.multi.add_command(label="twelves multiplication table", command=lambda:[self.tbles("m", 1)])


        # Division Tables
        self.div = tk.Menu(self.menu)
        self.menu.add_cascade(label="Division Tables", menu=self.div)
        self.div.add_command(label="ones division table",  command=lambda:[self.tbles("d", 1)])
        self.div.add_command(label="twos division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_command(label="threes division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_separator()
        self.div.add_command(label="fours division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_command(label="fives division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_command(label="sixes  division tables", command=lambda:[self.tbles("d", 1)])
        self.div.add_separator()
        self.div.add_command(label="sevens division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_command(label="eights division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_command(label="nines division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_separator()
        self.div.add_command(label="tens division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_command(label="elevens division table", command=lambda:[self.tbles("d", 1)])
        self.div.add_command(label="twelves division table", command=lambda:[self.tbles("d", 1)])

        # Prime Numbers
        self.prime = tk.Menu(self.menu)
        self.menu.add_cascade(label="Which is the prime number?", menu=self.prime)
        self.prime.add_command(label="1 to 10", command=self.iw)
        self.prime.add_command(label="10 to 20", command=self.iw)


        #Fraction of the pie
        self.frac = tk.Menu(self.menu)
        self.menu.add_cascade(label="Pie fractions", menu=self.frac)
        self.frac.add_command(label="What fraction of the pie is the slice?", command=self.iw)
        self.frac.add_command(label="What fraction of the pie is remaining?", command=self.iw)

        self.helpmenu = tk.Menu(self.menu)
        self.menu.add_cascade(label="Help", command=self.iw)
        self.helpmenu.add_command(label="About...", command=self.iw)
        self.root.config(menu=self.menu)


#Table brings up a menu where the use chooses an answer to an addition, subtraction, multiplication or division problem.
    def tbles(self, asmd, no):
        import random
        arandomno = random.randrange(1,12)

        #This if then stmt is to make up addition, sub, multi and div problems

        #Addition Tables
        #asmd specifies where to use addition, subtraction, multiplication or division
        #prob shows the problem
        #ansx and #ansy are incorrect answers to the problem
        #corans is the correct answer to the problem
        #ans is the list of possible answers to the problem

        if asmd == "a":
            prob = str(arandomno) + " +" + str(no) + "="  #Show the problem
            ansx = no + random.randrange(1,12)  #Make a wrong answer
            ansy = no + random.randrange(1, 12)  # Make a wrong answer
            corans = arandomno + no   #Calculate the correct answer
            ans = [ansx, ansy, corans]  # Make a list of answers


        #Subtraction
        elif asmd == "s":
            result = 'High' if x > 10 else 'Low'
            prob = str(arandomno) + " -" + str(no)
            ansx = no - random.randrange(1,12)
            ansy = no - random.randrange(1, 12)
            corans = arandomno - no
            ans = [ansx, ansy, corans]

        #Multiplication
        elif asmd == "m":
            prob = str(arandomno) + " X" + str(no)
            ansx = no * random.randrange(1, 12)
            ansy = no * random.randrange(1, 12)
            corans = arandomno * no
            ans = [ansx, ansy, corans]

        #Division
        else:
            prob = str(arandomno) + " /" + str(no)
            ansx = no / random.randrange(1, 12)
            ansy = no / random.randrange(1, 12)
            corans = arandomno / no
            ans = [ansx, ansy, corans]
        print (ans)


        random.shuffle(ans)
        print (ans)

        self.mmframe.destroy()
        self.mmframe = tk.Frame(root)
        self.mmframe.grid(row=0, column=0, sticky=tk.W + tk.E, padx = mypadx, pady = mypady)

        self.probsleft = tk.Label(self.mmframe, text="Problems left", bg=labcol, font=myfont, relief="groove")
        self.probsleft.config(height=myheight2, width=mywidth2)
        self.probsleft.grid(row=1, column=1, sticky=tk.W + tk.E, padx = mypadx, pady = mypady)

        self.prob = tk.Label(self.mmframe, text=prob, bg="snow", font=myfont,relief="groove")
        self.prob.config(height=myheight2, width=mywidth2)
        self.prob.grid(row=1, column=2, sticky=tk.W + tk.E,padx = mypadx, pady = mypady)

        self.score = tk.Label(self.mmframe, text="Score", bg=labcol, font=myfont, relief="groove")
        self.score.config(height=myheight2, width=mywidth2)
        self.score.grid(row=1, column=3, sticky=tk.W + tk.E, padx= mypadx, pady = mypady)

        self.answera = tk.Button(self.mmframe, text=ans[0], bg=anscol, font=myfont, relief="groove")
        self.answera.config(height=myheight3, width=mywidth2)
        self.answera.grid(row=2, column=1, sticky=tk.W + tk.E,padx= mypadx, pady = mypady)

        self.answerb = tk.Button(self.mmframe, text=ans[1], bg=anscol, font=myfont, relief="groove")
        self.answerb.config(height=myheight3, width=mywidth2)
        self.answerb.grid(row=2, column=2, sticky=tk.W + tk.E,padx= mypadx, pady = mypady)

        self.answerc = tk.Button(self.mmframe, text=ans[2], bg=anscol, font=myfont, relief="groove")
        self.answerc.config(height=myheight3, width=mywidth2)
        self.answerc.grid(row=2, column=3, sticky=tk.W + tk.E,padx= mypadx, pady = mypady)

        self.instructions = tk.Label(self.mmframe, text="Select the answer from the yellow buttons.", \
                                     font=myfont, bg="light gray", relief="groove", wraplength = 400)
        self.instructions.config(height=myheight3, width=mywidth2)
        self.instructions.grid(row=4, column=1, sticky=tk.W + tk.E, padx=mypadx, pady= mypady)

        self.mainmenu = tk.Button(self.mmframe, text="Go to Main Menu", bg="red",font=myfont, relief="groove")
        self.mainmenu.config(height=myheight3, width=mywidth2)
        self.mainmenu.grid(row=4, column=2, sticky=tk.W + tk.E, padx=mypadx, pady= mypady)

        self.exit = tk.Button(self.mmframe, text="Exit", bg="red", font=myfont, relief="groove")
        self.exit.config(height=myheight3, width=mywidth2)
        self.exit.grid(row=4, column=3, sticky=tk.W + tk.E, padx=mypadx, pady=mypady)

    def iw(self):
        pass


m = Mathtasks(root)
root.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter destroy label inside labelFrame Nick_tkinter 3 4,546 Sep-17-2023, 03:38 PM
Last Post: munirashraf9821
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 775 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  [Tkinter] _tkinter.TclError: can't invoke "destroy" command: application has been destroyed knoxvilles_joker 6 15,561 Apr-25-2021, 08:41 PM
Last Post: knoxvilles_joker
  clear button destroy can't work jacklee26 1 4,096 Jul-07-2019, 03:44 AM
Last Post: DeaD_EyE
  destroy function issue SmokerX 8 4,690 Jan-26-2018, 11:21 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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