How to create Tkinter main menu

Viewed 355

I am currently creating a quiz game in Tkinter. This game consists of a login page, the quiz, a graph to show results and a pong game. The quiz and login use the Tkinter library for the GUI, the graph uses MatPlotLib and pong uses pygame. Is there any way that I would be able to link all of these modules in the main menu, for example creating a Tkinter GUI and then assigning a command to each button to launch the respective python files?

EDIT: Adding code that I have tried.

from tkinter import *
import sqlite3
import sys
import time
import importlib


importlib.import_module('Quiz')

class Menu:
    def __init__(self, master):
        
        #Setting up the window
        self.master = master
        self.master.geometry("1350x800+50+50")
        self.master.title("Main Menu")

        self.quizLaunch = Button(self.master, text="Quiz", command = quizApplication)
        self.quizLaunch.pack()

root = Tk()
Menu(root)
root.mainloop()
1 Answers

Yes, it is completely possible. You can do this by importing packages like what you do in normal codes. You will be needed to import the following libraries to embed matplotlib into tkinter.

import matplotlib
import pygame
from tkinter import *
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure

I recently made a basic GUI application using pygame in the python script along with tkinter library.

It would be great if you could post your code.

You can find the complete guide at: https://pythonprogramming.net/how-to-embed-matplotlib-graph-tkinter-gui/

Related