Skip to content
Advertisement

How to code a menu bar across your Pygame project

I have been struggling with merging my code.

I am creating an arcade game on Python and have a main file where I have an image and clickable assets which link to a game I have imported.

Now I am working on creating constant features in the game, including a menu bar which displays reminders, can change the volume and brightness setting etcetura.

However, I don’t know how to make this on my main project file. Could you help me out?

I am using Python Pygame, Tkinter and Turtle.

Advertisement

Answer

It sounds like you need to think some more about what exactly you want. Your question is rather vague and tkinter has several options that can be presented in various ways to a user for making selections. Below is a quick example of some ideas you may want to explore.tkinter widgets

import tkinter as tk
from tkinter import ttk

    
root = tk.Tk()
root.geometry("400x400")
root.resizable(False, False)
root.title("Sample")

menu = tk.Menu(root)
root.config(menu=menu)

file_menu = tk.Menu(menu, tearoff=0)
menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Quit", command=quit)
file_menu.add_command(label="Something", command=quit)
file_menu.add_command(label="New Option", command=quit)

label = tk.Label(root, text="Choose an option below", font="times 14")#label
label.pack()

items = ["Hi", "Something", "Bye"]
combo_box = ttk.Combobox(root, font=20, state="normal")#combo box
combo_box['values'] = items
combo_box.pack()

lblabel = tk.Label(root, text="Choose an item from the list", font="times 14")#label
lblabel.pack()

items_var = tk.StringVar(value=items)
list_box = tk.Listbox(root, listvariable=items_var, selectmode=tk.BROWSE)#list box
list_box.pack()

rblabel = tk.Label(root, text="Choose an option below", font="times 14")#label
rblabel.pack()

choices = tk.StringVar(value=items)
radio_button = ttk.Radiobutton(root, text="some_option")#radio button
radio_button.pack()


root.mainloop()
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement