Python Forum
[Tkinter] arrow key selection for menu
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] arrow key selection for menu
#1
I have the initial layout built. I will have to rebuild the menu as a subclass app definition as I was advised in my other thread to get key bind input events to work.

The goal is to have the menu initially with no highlighted items. as you activate a column to make a selection the header for that section highlights and you then highlight an option. You use the arrow keys to make your selections. As you move the arrow key left or right you move to a different column heading. The up and down keys make the selection highlight.

I just need help on the vernacular and what type of options to use. I can figure out the rest once I got something to chew on.

This is to replace a flash software piece for a movie replica fascimile for the costuming group I am in.

For reference this is the other thread:
https://python-forum.io/Thread-Tkinter-b...ss-counter

# Import module
from tkinter import *
import tkinter
from PIL import Image, ImageTk

import keyboard
import pynput
import pygame

pygame.init()
keys = pygame.key.get_pressed()

# Create object
root = tkinter.Tk()

# Adjust size
root.geometry("640x300")
root.configure(bg='black')

# Specify Grid
# options for grid:
# MINSIZE, PAD, UNIFORM, WEIGHT

Grid.rowconfigure(root,0,weight=1, uniform='a')
Grid.rowconfigure(root,1,weight=1, uniform='b')
Grid.rowconfigure(root,2,weight=1, uniform='b')
Grid.rowconfigure(root,3,weight=1, uniform='b')
Grid.rowconfigure(root,4,weight=1, uniform='b')
Grid.rowconfigure(root,5,weight=1, uniform='b')
Grid.rowconfigure(root,6,weight=1, uniform='b')
Grid.rowconfigure(root,7,weight=1, uniform='b')
Grid.rowconfigure(root,8,weight=1, uniform='b')
Grid.rowconfigure(root,9,weight=1, uniform='b')
Grid.columnconfigure(root,0,weight=1, uniform='d')
Grid.columnconfigure(root,1,weight=1, uniform='d')
Grid.columnconfigure(root,2,weight=1, uniform='d')
Grid.columnconfigure(root,3,weight=1, uniform='d')
Grid.columnconfigure(root,4,weight=1, uniform='d')
Grid.columnconfigure(root,5,weight=1, uniform='d')
Grid.columnconfigure(root,6,weight=1, uniform='d')
Grid.columnconfigure(root,7,weight=1, uniform='d')
#Grid.columnconfigure(root,4,weight=1, uniform='a')
#Grid.rowconfigure(root,0,row=0,weight=0)


# notes on different widget options other notes sections will be added for late rreference needs and 
# desired customizations.
# w = Canvas (master, option-value
# bd, bg, cursor, highlight color, width, height
# w = CheckButton(master, option=value)
# Title, activebackground, activeforeground, bg, command, font, image
# w=Entry(master, option=value)
# bd, bg, cursor, command, highlightcolor, width, height
# w=Label(master, option=value)
# bg, bd, command, font, image, width, height
# w = Listbox(master, option=value)
# hightlightcolor, bg, bd, font, image, width, height
# w = MenuButton(master, option=value)
# activebackground, activeforeground, bg, bd, cursor, image, width, height, highlightcolor
# w = Scrollbar(master, option=value)
# width, activebackground, bg, bd, cursor
# w = Text(master, option=value)
# highlightcolor, insertbackground, bg, font, image, width, height
# w = tk.menu button(parent, option, ...)
# activebackground, activeforeground, anchor, background or bg, cursor, compound, direction, disabledforeground, fg, font, height, highlightbackground, highlightcolor, highlightthickness, image, justify, menu, padx, pady, relief, state, takefocus, text, textvariable, underline, width, wraplength
#
#
#

#image files 
#photo = PhotoImage(file = r"c:\Menu_title.png") # old sentry gun menu title

# Specify Framesw = Frame(master, option=value)
# bg, bd, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, width


# Create Buttons
# master, option=value, ...
# activebackground, activeforeground, bd, bg, command, fg, font, height, highlightcolor, image, justify, padx, pady, relief, state, underline, width, wraplength
button_1 = Button(root,justify=CENTER,text="AUTO-REMOTE",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
button_2 = Button(root,justify=CENTER,text="HARD",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
button_3 = Button(root,justify=CENTER,text="SEMIHARD",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
button_4 = Button(root,justify=CENTER,text="SOFT",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
sbutton_1 = Button(root,justify=CENTER,text="BIO",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
sbutton_2 = Button(root,justify=CENTER,text="INERT",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
tsbutton_1 = Button(root,justify=CENTER,text="MULTI SPEC",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
tsbutton_2 = Button(root,justify=CENTER,text="INFRA RED",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
tsbutton_3 = Button(root,justify=CENTER,text="UV",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
wsbutton_1 = Button(root,justify=CENTER,text="SAFE",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
wsbutton_2 = Button(root,justify=CENTER,text="ARMED",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
isbutton_1 = Button(root,justify=CENTER,text="SEARCH",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
isbutton_2 = Button(root,justify=CENTER,text="TEST",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
isbutton_3 = Button(root,justify=CENTER,text="ENGAGED",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
isbutton_4 = Button(root,justify=CENTER,text="INTERROGATE",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
trbutton_1 = Button(root,justify=CENTER,text="AUTO",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
trbutton_2 = Button(root,justify=CENTER,text="SELECTIVE",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
smman = Button(root,justify=CENTER,text="MAN-OVERRIDE",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
smauto = Button(root,justify=CENTER,text="SEMI-AUTO",bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black',activebackground='yellow')
gun_1 = Button(root,borderwidth=7,bg='black',relief=RIDGE,disabledforeground='yellow',state=DISABLED,text="kp")
gun_2 = Button(root,borderwidth=7,bg='black',fg='yellow',disabledforeground='yellow',state=DISABLED,text="kp")
#header = Button(root, image = photo, compound = TOP) # image reference
headernew = Button(root, bg='black',state=DISABLED, fg='yellow',disabledforeground='yellow',highlightbackground='yellow',borderwidth=2,justify=CENTER, text="UA 571-C \n REMOTE SENTRY WEAPON SYSTEM")
syst = Button(root,bg='black',state=DISABLED, fg='yellow',disabledforeground='yellow',highlightbackground='yellow',borderwidth=2,justify=CENTER,text="SYSTEM \n   MODE")
weap = Button(root,bg='black',state=DISABLED, fg='yellow',disabledforeground='yellow',highlightbackground='yellow',borderwidth=2,justify=CENTER,text="WEAPON \n   STATUS")
iff = Button(root,bg='black',state=DISABLED, fg='yellow',disabledforeground='yellow',highlightbackground='yellow',borderwidth=2,justify=CENTER,text="IFF \n   STATUS")
test = Button(root,bg='black',state=DISABLED, fg='yellow',disabledforeground='yellow',highlightbackground='yellow',borderwidth=2,justify=CENTER,text="TEST \n   ROUTINE")
target = Button(root,bg='black',state=DISABLED, fg='yellow',disabledforeground='yellow',highlightbackground='yellow',borderwidth=2,justify=CENTER,text="TARGET PROFILE")
spectral = Button(root,bg='black',state=DISABLED, fg='yellow',disabledforeground='yellow',highlightbackground='yellow',borderwidth=2,justify=CENTER,text="SPECTRAL PROFILE")
ts = Button(root,bg='black',state=DISABLED, fg='yellow',disabledforeground='yellow',highlightbackground='yellow',borderwidth=2,justify=CENTER,text="TARGET SELECT")
# bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black'

# Set grid
# widget.grid(grid_options)
# column, columnspan, ipadx, ipady, padx, pady, row, rowspan, sticky
gun_1.grid(row=0,column=0,ipadx=2,ipady=2,padx=2,pady=2,sticky=W)
gun_2.grid(row=0,column=7,ipadx=2,ipady=2,padx=2,pady=2,sticky=E)
headernew.grid(row=0,column=1,columnspan=6,sticky="NSEW")
button_1.grid(row=2,column=0,columnspan=2,sticky="NSEW")
button_2.grid(row=9,column=0,columnspan=3,sticky="NSEW")
button_3.grid(row=8,column=0,columnspan=3,sticky="NSEW")
button_4.grid(row=7,column=0,columnspan=3,sticky="NSEW")
sbutton_1.grid(row=7,column=3,columnspan=2,sticky="NSEW")
sbutton_2.grid(row=8,column=3,columnspan=2,sticky="NSEW")
tsbutton_1.grid(row=7,column=5,columnspan=3,sticky="NSEW")
tsbutton_2.grid(row=8,column=5,columnspan=3,sticky="NSEW")
tsbutton_3.grid(row=9,column=5,columnspan=3,sticky="NSEW")
wsbutton_1.grid(row=2,column=2,columnspan=2,sticky="NSEW")
wsbutton_2.grid(row=3,column=2,columnspan=2,sticky="NSEW")
isbutton_1.grid(row=2,column=4,columnspan=2,sticky="NSEW")
isbutton_2.grid(row=3,column=4,columnspan=2,sticky="NSEW")
isbutton_3.grid(row=4,column=4,columnspan=2,sticky="NSEW")
isbutton_4.grid(row=5,column=4,columnspan=2,sticky="NSEW")
trbutton_1.grid(row=2,column=6,columnspan=2,sticky="NSEW")
trbutton_2.grid(row=3,column=6,columnspan=2,sticky="NSEW")
smman.grid(row=3,column=0,columnspan=2,sticky="NSEW")
smauto.grid(row=4,column=0,columnspan=2,sticky="NSEW")


syst.grid(row=1,column=0,columnspan=2,sticky="NSEW")
weap.grid(row=1,column=2,columnspan=2,sticky="NSEW")
iff.grid(row=1,column=4,columnspan=2,sticky="NSEW")
test.grid(row=1,column=6,columnspan=2,sticky="NSEW")
target.grid(row=6,column=0,columnspan=3,sticky="NSEW")
spectral.grid(row=6,column=3,columnspan=2,sticky="NSEW")
ts.grid(row=6,column=5,columnspan=3,sticky="NSEW")

while True:
# Execute tkinter
  root.mainloop()
  for event in pygame.event.get():
    if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_q:
        pygame.quit()
        sys.exit(0)
        quit()
        break
  if keys[pygame.K_w]:
    break
As always this is an awesome forum and everyone on it is an awesome help!
Reply
#2
Is this a tkinter problem or pygame?
Is it necessary to try mixing tkinter and pygame together because I don't think they play together nicely?
Reply
#3
I was meshing together anything I could find to make things work. I ended up settling on nothing but TKINTER.

pygame did not have a good menu or grid system built in. The only thing pygame has is a border option that tkinter does not have. But I may be able to side step that by using a background with the border and then overlaying the button grid arrays on top of it using only TKINTER.

I am only interested in using tkinter for the button actions as that is the only way I can get the buttons to layout like I am wanting.

Off hand the only methodology I can think of is to assign a numerical weight to each directional key press and then the value of x which the keypresses adjust equals a set look of the menu screen. The menu would appear to change with each keypress but you are really changing a mathematical value that sets the entire screens look. I just need to test the idea to even see if it is viable or not.

I am not aware of any other modules or libraries in python I can use to power button driven menu interface. If there are do please let me know so that I can do further research. With what almost a million individual libraries, it is quite possible there exists one written specifically for what I need that I am unaware of.

(Apr-13-2021, 04:33 PM)Yoriz Wrote: Is this a tkinter problem or pygame?
Is it necessary to try mixing tkinter and pygame together because I don't think they play together nicely?
Reply
#4
I used deque to group buttons together so you can rotate the active button, and then another deque to contain the header button and the deque groups.
There is a function start_with_first_selected that is set to False to get the behaviour you asked for of having nothing shown as selected, to do this it means the last button of each group is the active one but not yet shown until you rotate that group for the first time.
I think I prefer start_with_first_selected set to True so the first item of each group is active to begin with.

You will probably want to play around with the formatting of the headers to make them look different from the selections.

I commented out all pygame stuff.

# Import module
from collections import deque
from itertools import islice
from tkinter import *
import tkinter
# from PIL import Image, ImageTk

# import keyboard
# import pynput
# import pygame

# pygame.init()
# keys = pygame.key.get_pressed()

# Create object
root = tkinter.Tk()

# Adjust size
root.geometry("640x300")
root.configure(bg='black')

# Specify Grid
# options for grid:
# MINSIZE, PAD, UNIFORM, WEIGHT

Grid.rowconfigure(root, 0, weight=1, uniform='a')
Grid.rowconfigure(root, 1, weight=1, uniform='b')
Grid.rowconfigure(root, 2, weight=1, uniform='b')
Grid.rowconfigure(root, 3, weight=1, uniform='b')
Grid.rowconfigure(root, 4, weight=1, uniform='b')
Grid.rowconfigure(root, 5, weight=1, uniform='b')
Grid.rowconfigure(root, 6, weight=1, uniform='b')
Grid.rowconfigure(root, 7, weight=1, uniform='b')
Grid.rowconfigure(root, 8, weight=1, uniform='b')
Grid.rowconfigure(root, 9, weight=1, uniform='b')
Grid.columnconfigure(root, 0, weight=1, uniform='d')
Grid.columnconfigure(root, 1, weight=1, uniform='d')
Grid.columnconfigure(root, 2, weight=1, uniform='d')
Grid.columnconfigure(root, 3, weight=1, uniform='d')
Grid.columnconfigure(root, 4, weight=1, uniform='d')
Grid.columnconfigure(root, 5, weight=1, uniform='d')
Grid.columnconfigure(root, 6, weight=1, uniform='d')
Grid.columnconfigure(root, 7, weight=1, uniform='d')
#Grid.columnconfigure(root,4,weight=1, uniform='a')
# Grid.rowconfigure(root,0,row=0,weight=0)


# notes on different widget options other notes sections will be added for late rreference needs and
# desired customizations.
# w = Canvas (master, option-value
# bd, bg, cursor, highlight color, width, height
# w = CheckButton(master, option=value)
# Title, activebackground, activeforeground, bg, command, font, image
# w=Entry(master, option=value)
# bd, bg, cursor, command, highlightcolor, width, height
# w=Label(master, option=value)
# bg, bd, command, font, image, width, height
# w = Listbox(master, option=value)
# hightlightcolor, bg, bd, font, image, width, height
# w = MenuButton(master, option=value)
# activebackground, activeforeground, bg, bd, cursor, image, width, height, highlightcolor
# w = Scrollbar(master, option=value)
# width, activebackground, bg, bd, cursor
# w = Text(master, option=value)
# highlightcolor, insertbackground, bg, font, image, width, height
# w = tk.menu button(parent, option, ...)
# activebackground, activeforeground, anchor, background or bg, cursor, compound, direction, disabledforeground, fg, font, height, highlightbackground, highlightcolor, highlightthickness, image, justify, menu, padx, pady, relief, state, takefocus, text, textvariable, underline, width, wraplength
#
#
#

# image files
# photo = PhotoImage(file = r"c:\Menu_title.png") # old sentry gun menu title

# Specify Framesw = Frame(master, option=value)
# bg, bd, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, width


# Create Buttons
# master, option=value, ...
# activebackground, activeforeground, bd, bg, command, fg, font, height, highlightcolor, image, justify, padx, pady, relief, state, underline, width, wraplength
button_1 = Button(root, justify=CENTER, text="AUTO-REMOTE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
button_2 = Button(root, justify=CENTER, text="HARD", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
button_3 = Button(root, justify=CENTER, text="SEMIHARD", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
button_4 = Button(root, justify=CENTER, text="SOFT", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
sbutton_1 = Button(root, justify=CENTER, text="BIO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
sbutton_2 = Button(root, justify=CENTER, text="INERT", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
tsbutton_1 = Button(root, justify=CENTER, text="MULTI SPEC", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
tsbutton_2 = Button(root, justify=CENTER, text="INFRA RED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
tsbutton_3 = Button(root, justify=CENTER, text="UV", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
wsbutton_1 = Button(root, justify=CENTER, text="SAFE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
wsbutton_2 = Button(root, justify=CENTER, text="ARMED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
isbutton_1 = Button(root, justify=CENTER, text="SEARCH", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
isbutton_2 = Button(root, justify=CENTER, text="TEST", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
isbutton_3 = Button(root, justify=CENTER, text="ENGAGED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
isbutton_4 = Button(root, justify=CENTER, text="INTERROGATE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
trbutton_1 = Button(root, justify=CENTER, text="AUTO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
trbutton_2 = Button(root, justify=CENTER, text="SELECTIVE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
smman = Button(root, justify=CENTER, text="MAN-OVERRIDE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
smauto = Button(root, justify=CENTER, text="SEMI-AUTO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
gun_1 = Button(root, borderwidth=7, bg='black', relief=RIDGE,disabledforeground='yellow', state=DISABLED, text="kp")
gun_2 = Button(root, borderwidth=7, bg='black', fg='yellow',disabledforeground='yellow', state=DISABLED, text="kp")
# header = Button(root, image = photo, compound = TOP) # image reference
headernew = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="UA 571-C \n REMOTE SENTRY WEAPON SYSTEM")
syst = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="SYSTEM \n   MODE")
weap = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="WEAPON \n   STATUS")
iff = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="IFF \n   STATUS")
test = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TEST \n   ROUTINE")
target = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TARGET PROFILE")
spectral = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="SPECTRAL PROFILE")
ts = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TARGET SELECT")
# bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black'

# Set grid
# widget.grid(grid_options)
# column, columnspan, ipadx, ipady, padx, pady, row, rowspan, sticky
gun_1.grid(row=0, column=0, ipadx=2, ipady=2, padx=2, pady=2, sticky=W)
gun_2.grid(row=0, column=7, ipadx=2, ipady=2, padx=2, pady=2, sticky=E)
headernew.grid(row=0, column=1, columnspan=6, sticky="NSEW")
button_1.grid(row=2, column=0, columnspan=2, sticky="NSEW")
button_2.grid(row=9, column=0, columnspan=3, sticky="NSEW")
button_3.grid(row=8, column=0, columnspan=3, sticky="NSEW")
button_4.grid(row=7, column=0, columnspan=3, sticky="NSEW")
sbutton_1.grid(row=7, column=3, columnspan=2, sticky="NSEW")
sbutton_2.grid(row=8, column=3, columnspan=2, sticky="NSEW")
tsbutton_1.grid(row=7, column=5, columnspan=3, sticky="NSEW")
tsbutton_2.grid(row=8, column=5, columnspan=3, sticky="NSEW")
tsbutton_3.grid(row=9, column=5, columnspan=3, sticky="NSEW")
wsbutton_1.grid(row=2, column=2, columnspan=2, sticky="NSEW")
wsbutton_2.grid(row=3, column=2, columnspan=2, sticky="NSEW")
isbutton_1.grid(row=2, column=4, columnspan=2, sticky="NSEW")
isbutton_2.grid(row=3, column=4, columnspan=2, sticky="NSEW")
isbutton_3.grid(row=4, column=4, columnspan=2, sticky="NSEW")
isbutton_4.grid(row=5, column=4, columnspan=2, sticky="NSEW")
trbutton_1.grid(row=2, column=6, columnspan=2, sticky="NSEW")
trbutton_2.grid(row=3, column=6, columnspan=2, sticky="NSEW")
smman.grid(row=3, column=0, columnspan=2, sticky="NSEW")
smauto.grid(row=4, column=0, columnspan=2, sticky="NSEW")


syst.grid(row=1, column=0, columnspan=2, sticky="NSEW")
weap.grid(row=1, column=2, columnspan=2, sticky="NSEW")
iff.grid(row=1, column=4, columnspan=2, sticky="NSEW")
test.grid(row=1, column=6, columnspan=2, sticky="NSEW")
target.grid(row=6, column=0, columnspan=3, sticky="NSEW")
spectral.grid(row=6, column=3, columnspan=2, sticky="NSEW")
ts.grid(row=6, column=5, columnspan=3, sticky="NSEW")

group1 = deque((button_1, smman, smauto))
group2 = deque((wsbutton_1, wsbutton_2))
group3 = deque((isbutton_1, isbutton_2, isbutton_3, isbutton_4))
group4 = deque((trbutton_1, trbutton_2))
group5 = deque((button_4, button_3, button_2))
group6 = deque((sbutton_1, sbutton_2))
group7 = deque((tsbutton_1, tsbutton_2, tsbutton_3))
header_group = deque(((syst, group1), (weap, group2),
                     (iff, group3), (test, group4),
                     (target, group5), (spectral, group6),
                     (ts, group7)))


def toggle_button_group(button_group):
    button_group[0].config(
        foreground='black', background='yellow', relief='sunken')
    for button in islice(button_group, 1, None):
        button.config(foreground='yellow', background='black', relief='raised')


def toggle_header_group(header_group):
    header_group[0][0].config(
        disabledforeground='black', background='yellow', relief='sunken')
    for button in islice(header_group, 1, None):
        button[0].config(disabledforeground='yellow',
                         background='black', relief='raised')


def start_with_first_selected(first_selected=False):
    if first_selected:
        toggle_button_group(group1)
        toggle_button_group(group2)
        toggle_button_group(group3)
        toggle_button_group(group4)
        toggle_button_group(group5)
        toggle_button_group(group6)
        toggle_button_group(group7)
    else:
        # set last of each group to selected
        group1.rotate(1)
        group2.rotate(1)
        group3.rotate(1)
        group4.rotate(1)
        group5.rotate(1)
        group6.rotate(1)
        group7.rotate(1)


start_with_first_selected(False)
toggle_header_group(header_group)


def on_down(event):
    group = header_group[0][1]
    group.rotate(-1)
    toggle_button_group(group)


def on_up(event):
    group = header_group[0][1]
    group.rotate(1)
    toggle_button_group(group)


def on_left(event):
    header_group.rotate(1)
    toggle_header_group(header_group)


def on_right(event):
    header_group.rotate(-1)
    toggle_header_group(header_group)


root.bind('<Down>', on_down)
root.bind('<Up>', on_up)
root.bind('<Left>', on_left)
root.bind('<Right>', on_right)

# while True:
# # Execute tkinter
root.mainloop()
#   for event in pygame.event.get():
#     if event.type == pygame.KEYDOWN:
#       if event.key == pygame.K_q:
#         pygame.quit()
#         sys.exit(0)
#         quit()
#         break
#   if keys[pygame.K_w]:
#     break
Reply
#5
(Apr-14-2021, 06:57 PM)Yoriz Wrote: I used deque to group buttons together so you can rotate the active button, and then another deque to contain the header button and the deque groups.
There is a function start_with_first_selected that is set to False to get the behaviour you asked for of having nothing shown as selected, to do this it means the last button of each group is the active one but not yet shown until you rotate that group for the first time.
I think I prefer start_with_first_selected set to True so the first item of each group is active to begin with.

You will probably want to play around with the formatting of the headers to make them look different from the selections.

I commented out all pygame stuff.

# Import module
from collections import deque
from itertools import islice
from tkinter import *
import tkinter
# from PIL import Image, ImageTk

# import keyboard
# import pynput
# import pygame

# pygame.init()
# keys = pygame.key.get_pressed()

# Create object
root = tkinter.Tk()

# Adjust size
root.geometry("640x300")
root.configure(bg='black')

# Specify Grid
# options for grid:
# MINSIZE, PAD, UNIFORM, WEIGHT

Grid.rowconfigure(root, 0, weight=1, uniform='a')
Grid.rowconfigure(root, 1, weight=1, uniform='b')
Grid.rowconfigure(root, 2, weight=1, uniform='b')
Grid.rowconfigure(root, 3, weight=1, uniform='b')
Grid.rowconfigure(root, 4, weight=1, uniform='b')
Grid.rowconfigure(root, 5, weight=1, uniform='b')
Grid.rowconfigure(root, 6, weight=1, uniform='b')
Grid.rowconfigure(root, 7, weight=1, uniform='b')
Grid.rowconfigure(root, 8, weight=1, uniform='b')
Grid.rowconfigure(root, 9, weight=1, uniform='b')
Grid.columnconfigure(root, 0, weight=1, uniform='d')
Grid.columnconfigure(root, 1, weight=1, uniform='d')
Grid.columnconfigure(root, 2, weight=1, uniform='d')
Grid.columnconfigure(root, 3, weight=1, uniform='d')
Grid.columnconfigure(root, 4, weight=1, uniform='d')
Grid.columnconfigure(root, 5, weight=1, uniform='d')
Grid.columnconfigure(root, 6, weight=1, uniform='d')
Grid.columnconfigure(root, 7, weight=1, uniform='d')
#Grid.columnconfigure(root,4,weight=1, uniform='a')
# Grid.rowconfigure(root,0,row=0,weight=0)


# notes on different widget options other notes sections will be added for late rreference needs and
# desired customizations.
# w = Canvas (master, option-value
# bd, bg, cursor, highlight color, width, height
# w = CheckButton(master, option=value)
# Title, activebackground, activeforeground, bg, command, font, image
# w=Entry(master, option=value)
# bd, bg, cursor, command, highlightcolor, width, height
# w=Label(master, option=value)
# bg, bd, command, font, image, width, height
# w = Listbox(master, option=value)
# hightlightcolor, bg, bd, font, image, width, height
# w = MenuButton(master, option=value)
# activebackground, activeforeground, bg, bd, cursor, image, width, height, highlightcolor
# w = Scrollbar(master, option=value)
# width, activebackground, bg, bd, cursor
# w = Text(master, option=value)
# highlightcolor, insertbackground, bg, font, image, width, height
# w = tk.menu button(parent, option, ...)
# activebackground, activeforeground, anchor, background or bg, cursor, compound, direction, disabledforeground, fg, font, height, highlightbackground, highlightcolor, highlightthickness, image, justify, menu, padx, pady, relief, state, takefocus, text, textvariable, underline, width, wraplength
#
#
#

# image files
# photo = PhotoImage(file = r"c:\Menu_title.png") # old sentry gun menu title

# Specify Framesw = Frame(master, option=value)
# bg, bd, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, width


# Create Buttons
# master, option=value, ...
# activebackground, activeforeground, bd, bg, command, fg, font, height, highlightcolor, image, justify, padx, pady, relief, state, underline, width, wraplength
button_1 = Button(root, justify=CENTER, text="AUTO-REMOTE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
button_2 = Button(root, justify=CENTER, text="HARD", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
button_3 = Button(root, justify=CENTER, text="SEMIHARD", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
button_4 = Button(root, justify=CENTER, text="SOFT", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
sbutton_1 = Button(root, justify=CENTER, text="BIO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
sbutton_2 = Button(root, justify=CENTER, text="INERT", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
tsbutton_1 = Button(root, justify=CENTER, text="MULTI SPEC", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
tsbutton_2 = Button(root, justify=CENTER, text="INFRA RED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
tsbutton_3 = Button(root, justify=CENTER, text="UV", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
wsbutton_1 = Button(root, justify=CENTER, text="SAFE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
wsbutton_2 = Button(root, justify=CENTER, text="ARMED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
isbutton_1 = Button(root, justify=CENTER, text="SEARCH", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
isbutton_2 = Button(root, justify=CENTER, text="TEST", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
isbutton_3 = Button(root, justify=CENTER, text="ENGAGED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
isbutton_4 = Button(root, justify=CENTER, text="INTERROGATE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
trbutton_1 = Button(root, justify=CENTER, text="AUTO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
trbutton_2 = Button(root, justify=CENTER, text="SELECTIVE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
smman = Button(root, justify=CENTER, text="MAN-OVERRIDE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
smauto = Button(root, justify=CENTER, text="SEMI-AUTO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
gun_1 = Button(root, borderwidth=7, bg='black', relief=RIDGE,disabledforeground='yellow', state=DISABLED, text="kp")
gun_2 = Button(root, borderwidth=7, bg='black', fg='yellow',disabledforeground='yellow', state=DISABLED, text="kp")
# header = Button(root, image = photo, compound = TOP) # image reference
headernew = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="UA 571-C \n REMOTE SENTRY WEAPON SYSTEM")
syst = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="SYSTEM \n   MODE")
weap = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="WEAPON \n   STATUS")
iff = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="IFF \n   STATUS")
test = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TEST \n   ROUTINE")
target = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TARGET PROFILE")
spectral = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="SPECTRAL PROFILE")
ts = Button(root, bg='black', state=DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TARGET SELECT")
# bg='black', fg='yellow', highlightbackground='yellow', highlightcolor='black'

# Set grid
# widget.grid(grid_options)
# column, columnspan, ipadx, ipady, padx, pady, row, rowspan, sticky
gun_1.grid(row=0, column=0, ipadx=2, ipady=2, padx=2, pady=2, sticky=W)
gun_2.grid(row=0, column=7, ipadx=2, ipady=2, padx=2, pady=2, sticky=E)
headernew.grid(row=0, column=1, columnspan=6, sticky="NSEW")
button_1.grid(row=2, column=0, columnspan=2, sticky="NSEW")
button_2.grid(row=9, column=0, columnspan=3, sticky="NSEW")
button_3.grid(row=8, column=0, columnspan=3, sticky="NSEW")
button_4.grid(row=7, column=0, columnspan=3, sticky="NSEW")
sbutton_1.grid(row=7, column=3, columnspan=2, sticky="NSEW")
sbutton_2.grid(row=8, column=3, columnspan=2, sticky="NSEW")
tsbutton_1.grid(row=7, column=5, columnspan=3, sticky="NSEW")
tsbutton_2.grid(row=8, column=5, columnspan=3, sticky="NSEW")
tsbutton_3.grid(row=9, column=5, columnspan=3, sticky="NSEW")
wsbutton_1.grid(row=2, column=2, columnspan=2, sticky="NSEW")
wsbutton_2.grid(row=3, column=2, columnspan=2, sticky="NSEW")
isbutton_1.grid(row=2, column=4, columnspan=2, sticky="NSEW")
isbutton_2.grid(row=3, column=4, columnspan=2, sticky="NSEW")
isbutton_3.grid(row=4, column=4, columnspan=2, sticky="NSEW")
isbutton_4.grid(row=5, column=4, columnspan=2, sticky="NSEW")
trbutton_1.grid(row=2, column=6, columnspan=2, sticky="NSEW")
trbutton_2.grid(row=3, column=6, columnspan=2, sticky="NSEW")
smman.grid(row=3, column=0, columnspan=2, sticky="NSEW")
smauto.grid(row=4, column=0, columnspan=2, sticky="NSEW")


syst.grid(row=1, column=0, columnspan=2, sticky="NSEW")
weap.grid(row=1, column=2, columnspan=2, sticky="NSEW")
iff.grid(row=1, column=4, columnspan=2, sticky="NSEW")
test.grid(row=1, column=6, columnspan=2, sticky="NSEW")
target.grid(row=6, column=0, columnspan=3, sticky="NSEW")
spectral.grid(row=6, column=3, columnspan=2, sticky="NSEW")
ts.grid(row=6, column=5, columnspan=3, sticky="NSEW")

group1 = deque((button_1, smman, smauto))
group2 = deque((wsbutton_1, wsbutton_2))
group3 = deque((isbutton_1, isbutton_2, isbutton_3, isbutton_4))
group4 = deque((trbutton_1, trbutton_2))
group5 = deque((button_4, button_3, button_2))
group6 = deque((sbutton_1, sbutton_2))
group7 = deque((tsbutton_1, tsbutton_2, tsbutton_3))
header_group = deque(((syst, group1), (weap, group2),
                     (iff, group3), (test, group4),
                     (target, group5), (spectral, group6),
                     (ts, group7)))


def toggle_button_group(button_group):
    button_group[0].config(
        foreground='black', background='yellow', relief='sunken')
    for button in islice(button_group, 1, None):
        button.config(foreground='yellow', background='black', relief='raised')


def toggle_header_group(header_group):
    header_group[0][0].config(
        disabledforeground='black', background='yellow', relief='sunken')
    for button in islice(header_group, 1, None):
        button[0].config(disabledforeground='yellow',
                         background='black', relief='raised')


def start_with_first_selected(first_selected=False):
    if first_selected:
        toggle_button_group(group1)
        toggle_button_group(group2)
        toggle_button_group(group3)
        toggle_button_group(group4)
        toggle_button_group(group5)
        toggle_button_group(group6)
        toggle_button_group(group7)
    else:
        # set last of each group to selected
        group1.rotate(1)
        group2.rotate(1)
        group3.rotate(1)
        group4.rotate(1)
        group5.rotate(1)
        group6.rotate(1)
        group7.rotate(1)


start_with_first_selected(False)
toggle_header_group(header_group)


def on_down(event):
    group = header_group[0][1]
    group.rotate(-1)
    toggle_button_group(group)


def on_up(event):
    group = header_group[0][1]
    group.rotate(1)
    toggle_button_group(group)


def on_left(event):
    header_group.rotate(1)
    toggle_header_group(header_group)


def on_right(event):
    header_group.rotate(-1)
    toggle_header_group(header_group)


root.bind('<Down>', on_down)
root.bind('<Up>', on_up)
root.bind('<Left>', on_left)
root.bind('<Right>', on_right)

# while True:
# # Execute tkinter
root.mainloop()
#   for event in pygame.event.get():
#     if event.type == pygame.KEYDOWN:
#       if event.key == pygame.K_q:
#         pygame.quit()
#         sys.exit(0)
#         quit()
#         break
#   if keys[pygame.K_w]:
#     break

Thanks! I will give that a go this weekend. Your help is greatly appreciated. The more I do this stuff the more I learn.
Reply
#6
This works exactly the way I wanted so thanks there. I will just need to tweak the code to work with my splash screen setup but that is no big deal. I will post the code once I get that hashed out.

Thanks a bunch for the help. The grouping took me a bit to wrap my head around as programming is something I can do but I would not say it is something that comes easily or that I am good at. But I will bulldog through the problem and force the issue to a conclusion, even if I annoy some folks in the process, unfortunately.
Reply
#7
I have added sound to the menu clicks.

import tkinter as tk
from tkinter import *
#import PIL.ImageTk
#import image
#import PIL
#import PIL.Image
import tkinter.ttk as ttk
import datetime as dt
import time
import os
from tkinter import messagebox
from collections import deque
from itertools import islice
from threading import Thread
from playsound import playsound

#
# global variables will be declared here
GUN = ""


# end global variables section
#
# This is the initial screen that loads and then disappears after 8 seconds 
# I used 3 images to make the main deal.  The issue was that pygame allowed for line draws
# tkinter only allows for drawing of boxes.  
# should this change I will change from using images.
class SplashFrame(tk.Toplevel):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.geometry('640x400')
        self.title("Iniitaling")
        self.img = tk.PhotoImage(file='load5.png')
        self.configure(background='black')
        self.overrideredirect(True)
        tk.Grid.rowconfigure(self, 0, weight=1, uniform='a')
        tk.Grid.columnconfigure(self, 0, weight=1, uniform='a')
        tk.Grid.rowconfigure(self, 1, weight=1, uniform='a')
        tk.Grid.rowconfigure(self, 2, weight=1, uniform='a')
        tk.Grid.columnconfigure(self, 1, weight=1, uniform='a')
        tk.Grid.columnconfigure(self, 2, weight=1, uniform='a')
        self.leftimage = PhotoImage(file='loadleft22.png')
        left = ttk.Label(self, style="TLabel", image=self.leftimage)
        left.grid(row=2, column=0, sticky="NSEW")
        self.rightimage = PhotoImage(file='loadright3.png')
        right = ttk.Label(self, style="TLabel", image=self.rightimage)
        right.grid(row=2, column=2, sticky="NSEW")
        btn = tk.Label(self, image=self.img)
        btn.grid(row=0, rowspan=2, column=0, columnspan=3, sticky="NSEW")
        styled = ttk.Style()
        styled.theme_use('clam')
        styled.configure("TLabel", background='black', darkcolor='black', bordercolor='black', relief='none', lightcolor='black', highlightcolor='black', foreground='black', shiftrelief=-5, highlightthickness=0, width=0, anchor="NSEW")
        styled.configure("Horizontal.TProgressbar", foreground = 'black', background = 'yellow', bordercolor='black', darkcolor='black', throughcolor='black', lightcolor='black')
        loadingbar = ttk.Progressbar(self, style="Horizontal.TProgressbar", orient="horizontal", length = 200, mode='indeterminate', maximum=100)
        loadingbar.grid(row=2, column=1, sticky="NEW")
        loadingbar.start([78])
        self.overrideredirect(True)
# self.after has a timer in msecs.  Just change this to your desired value.  I have logic on loading bar set for 8 seconds so if you change that
# you will need to adjust the loadingbar.start number.  Remember it is 200 units long and you divide that by the time in msecs to figure out how to divide up the movement
        self.after(1000, self.destroy)
#
# End of splash screen defined class and related functions
#




#------------begin select screen------------------------------
# Begin select menu defined class and related functions
# This is the script's core window so more code will be present here than in other sections
#  
# This is the next screen to load after the initial splash screen
class TkApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.geometry('640x400')
        self.title("Select Screen")
        self.configure(bg='black') 
        self.gun = tk.StringVar()
        self.gun.set(GUN)
        # Specify Grid 
        tk.Grid.rowconfigure(self, 0, weight=1, uniform='a')
        tk.Grid.rowconfigure(self, 1, weight=1, uniform='b')
        tk.Grid.rowconfigure(self, 2, weight=1, uniform='b')
        tk.Grid.rowconfigure(self, 3, weight=1, uniform='b')
        tk.Grid.rowconfigure(self, 4, weight=1, uniform='b')
        tk.Grid.rowconfigure(self, 5, weight=1, uniform='b')
        tk.Grid.rowconfigure(self, 6, weight=1, uniform='b')
        tk.Grid.rowconfigure(self, 7, weight=1, uniform='b')
        tk.Grid.rowconfigure(self, 8, weight=1, uniform='b')
        tk.Grid.rowconfigure(self, 9, weight=1, uniform='b')
        tk.Grid.columnconfigure(self, 0, weight=1, uniform='d')
        tk.Grid.columnconfigure(self, 1, weight=1, uniform='d')
        tk.Grid.columnconfigure(self, 2, weight=1, uniform='d')
        tk.Grid.columnconfigure(self, 3, weight=1, uniform='d')
        tk.Grid.columnconfigure(self, 4, weight=1, uniform='d')
        tk.Grid.columnconfigure(self, 5, weight=1, uniform='d')
        tk.Grid.columnconfigure(self, 6, weight=1, uniform='d')
        tk.Grid.columnconfigure(self, 7, weight=1, uniform='d')


        button_1 = tk.Button(self, justify=tk.CENTER, text="AUTO-REMOTE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        button_2 = tk.Button(self, justify=tk.CENTER, text="HARD", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        button_3 = tk.Button(self, justify=tk.CENTER, text="SEMIHARD", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        button_4 = tk.Button(self, justify=tk.CENTER, text="SOFT", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        sbutton_1 = tk.Button(self, justify=tk.CENTER, text="BIO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        sbutton_2 = tk.Button(self, justify=tk.CENTER, text="INERT", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        tsbutton_1 = tk.Button(self, justify=tk.CENTER, text="MULTI SPEC", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        tsbutton_2 = tk.Button(self, justify=tk.CENTER, text="INFRA RED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        tsbutton_3 = tk.Button(self, justify=tk.CENTER, text="UV", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        wsbutton_1 = tk.Button(self, justify=tk.CENTER, text="SAFE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        wsbutton_2 = tk.Button(self, justify=tk.CENTER, text="ARMED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        isbutton_1 = tk.Button(self, justify=tk.CENTER, text="SEARCH", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        isbutton_2 = tk.Button(self, justify=tk.CENTER, text="TEST", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        isbutton_3 = tk.Button(self, justify=tk.CENTER, text="ENGAGED", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        isbutton_4 = tk.Button(self, justify=tk.CENTER, text="INTERROGATE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        trbutton_1 = tk.Button(self, justify=tk.CENTER, text="AUTO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        trbutton_2 = tk.Button(self, justify=tk.CENTER, text="SELECTIVE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        smman = tk.Button(self, justify=tk.CENTER, text="MAN-OVERRIDE", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        smauto = tk.Button(self, justify=tk.CENTER, text="SEMI-AUTO", bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        # displays gun id on top left and right of screen
        gun_1 = tk.Button(self, borderwidth=7,bg='black',fg='yellow',disabledforeground='yellow',state=tk.DISABLED,textvariable=self.gun, highlightcolor = 'yellow')
        gun_2 = tk.Button(self, borderwidth=7,bg='black',fg='yellow',disabledforeground='yellow',state=tk.DISABLED,textvariable=self.gun)
        headernew = tk.Button(self, bg='black', state=tk.DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="UA         571-C \n REMOTE SENTRY WEAPON SYSTEM")
        syst = tk.Button(self, bg='black', state=tk.DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="SYSTEM \n   MODE")
        weap = tk.Button(self, bg='black', state=tk.DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="WEAPON \n   STATUS")
        iff = tk.Button(self, bg='black', state=tk.DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="IFF \n   STATUS")
        test = tk.Button(self, bg='black', state=tk.DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TEST \n   ROUTINE")
        target = tk.Button(self, bg='black', state=tk.DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TARGET PROFILE")
        spectral = tk.Button(self, bg='black', state=tk.DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="SPECTRAL PROFILE")
        ts = tk.Button(self, bg='black', state=tk.DISABLED, fg='yellow', disabledforeground='yellow',highlightbackground='yellow', borderwidth=2, justify=CENTER, text="TARGET SELECT")
        gun_1.grid(row=0, column=0, ipadx=2, ipady=2, padx=2, pady=2, sticky=W)
        gun_2.grid(row=0, column=7, ipadx=2, ipady=2, padx=2, pady=2, sticky=E)
        headernew.grid(row=0, column=1, columnspan=6, sticky="NSEW")
        button_1.grid(row=2, column=0, columnspan=2, sticky="NSEW")
        button_2.grid(row=9, column=0, columnspan=3, sticky="NSEW")
        button_3.grid(row=8, column=0, columnspan=3, sticky="NSEW")
        button_4.grid(row=7, column=0, columnspan=3, sticky="NSEW")
        sbutton_1.grid(row=7, column=3, columnspan=2, sticky="NSEW")
        sbutton_2.grid(row=8, column=3, columnspan=2, sticky="NSEW")
        tsbutton_1.grid(row=7, column=5, columnspan=3, sticky="NSEW")
        tsbutton_2.grid(row=8, column=5, columnspan=3, sticky="NSEW")
        tsbutton_3.grid(row=9, column=5, columnspan=3, sticky="NSEW")
        wsbutton_1.grid(row=2, column=2, columnspan=2, sticky="NSEW")
        wsbutton_2.grid(row=3, column=2, columnspan=2, sticky="NSEW")
        isbutton_1.grid(row=2, column=4, columnspan=2, sticky="NSEW")
        isbutton_2.grid(row=3, column=4, columnspan=2, sticky="NSEW")
        isbutton_3.grid(row=4, column=4, columnspan=2, sticky="NSEW")
        isbutton_4.grid(row=5, column=4, columnspan=2, sticky="NSEW")
        trbutton_1.grid(row=2, column=6, columnspan=2, sticky="NSEW")
        trbutton_2.grid(row=3, column=6, columnspan=2, sticky="NSEW")
        smman.grid(row=3, column=0, columnspan=2, sticky="NSEW")
        smauto.grid(row=4, column=0, columnspan=2, sticky="NSEW") 
        syst.grid(row=1, column=0, columnspan=2, sticky="NSEW")
        weap.grid(row=1, column=2, columnspan=2, sticky="NSEW")
        iff.grid(row=1, column=4, columnspan=2, sticky="NSEW")
        test.grid(row=1, column=6, columnspan=2, sticky="NSEW")
        target.grid(row=6, column=0, columnspan=3, sticky="NSEW")
        spectral.grid(row=6, column=3, columnspan=2, sticky="NSEW")
        ts.grid(row=6, column=5, columnspan=3, sticky="NSEW")
        # this quits by clicking a button labeled q
        quit = tk.Button(self, bg='black', fg='yellow', text='q', command=self.quit)
        quit.grid(row=8,column=0,sticky="SW")
        self.bind('<KeyPress-Down>', self.on_down)
        self.bind("<Up>", self.on_up)
        self.bind("<Left>", self.on_left)
        self.bind("<Right>", self.on_right)
        self.bind("<KeyPress-a>", self.on_keypress_a)
        self.bind("<KeyPress-b>", self.on_keypress_b)
        self.bind("<KeyPress-c>", self.on_keypress_c)
        self.bind("<KeyPress-d>", self.on_keypress_d)
        self.bind("<KeyPress-q>", self.on_keypress_q)
        tk.Button(self, text='SecondFrame', command=self.on_button, bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow').grid(row=9, column=0, sticky="SW")
        self.create_splashframe()
        # These are the bind key definitions
        self.bind("<KeyPress-r>", self.on_keypress_r)
        self.bind("<KeyPress-space>", self.on_keypress_space)
        self.bind("<KeyPress-k>", self.on_keypress_k)
        self.group1 = deque((button_1, smman, smauto))
        self.group2 = deque((wsbutton_1, wsbutton_2))
        self.group3 = deque((isbutton_1, isbutton_2, isbutton_3, isbutton_4))
        self.group4 = deque((trbutton_1, trbutton_2))
        self.group5 = deque((button_4, button_3, button_2))
        self.group6 = deque((sbutton_1, sbutton_2))
        self.group7 = deque((tsbutton_1, tsbutton_2, tsbutton_3))
        self.header_group = deque(((syst, self.group1), (weap, self.group2),(iff, self.group3), (test, self.group4),(target, self.group5), (spectral, self.group6),(ts, self.group7)))
        self.start_with_first_selected(False)
        self.toggle_header_group(self.header_group) 
 
    def toggle_button_group(self, button_group):
        button_group[0].config(foreground='black', background='yellow', relief='sunken')
        for button in islice(button_group, 1, None):
            button.config(foreground='yellow', background='black', relief='raised')
 
 
    def toggle_header_group(self, header_group):
        header_group[0][0].config(disabledforeground='black', background='yellow', relief='sunken')
        for button in islice(self.header_group, 1, None): 
            button[0].config(disabledforeground='yellow',background='black', relief='raised')
 
 
    def start_with_first_selected(self, first_selected=False):
        if first_selected:
           toggle_button_group(self.group1)
           toggle_button_group(self.group2)
           toggle_button_group(self.group3)
           toggle_button_group(self.group4)
           toggle_button_group(self.group5)
           toggle_button_group(self.group6)
           toggle_button_group(self.group7)
        else:
        # set last of each group to selected
           self.group1.rotate(1)
           self.group2.rotate(1)
           self.group3.rotate(1)
           self.group4.rotate(1)
           self.group5.rotate(1)
           self.group6.rotate(1)
           self.group7.rotate(1)
        

 
    def on_down(self, evet):
       group = self.header_group[0][1]
       group.rotate(-1)
       self.toggle_button_group(group)
       playsound("click1.mp3")
  
    def on_up(self, evet):
       group = self.header_group[0][1]
       group.rotate(1)
       self.toggle_button_group(group)
       playsound("click1.mp3")
 
    def on_left(self, evet):
       self.header_group.rotate(1)
       self.toggle_header_group(self.header_group)
       playsound("click1.mp3")
  
    def on_right(self, evet):
       self.header_group.rotate(-1)
       self.toggle_header_group(self.header_group)
       playsound("click1.mp3")





 # this appears to launch the initial window
    def create_splashframe(self):
        splashframe = SplashFrame(self)
        self.withdraw()
        self.wait_window(splashframe)
        self.deiconify()
# this launches the next screen, the fire select screen 
    def on_button(self):
        secondframe = SecondFrame(self)
        self.withdraw()
        self.wait_window(secondframe)
        self.deiconify()

    def kudos(self):
        kudosframe = KudosFrame(self)
        self.withdraw()
        self.wait_window(kudosframe)
        self.deiconify()

    def on_keypress_k(self, evet):
        print("k pressed")
        self.kudos()
        playsound("click1.mp3")
    # these work
    def on_keypress_a(self, evet):
        which_gun = self.gun.get()
        which_gun = "A"
        self.gun.set(which_gun)
        playsound("click1.mp3")
    def on_keypress_b(self, evet):
        which_gun = self.gun.get()
        which_gun = "B"
        self.gun.set(which_gun)
        playsound("click1.mp3")
    def on_keypress_c(self, evet):
        which_gun = self.gun.get()
        which_gun = "C"
        self.gun.set(which_gun)
        playsound("click1.mp3")
    def on_keypress_d(self, evet):
        which_gun = self.gun.get()
        which_gun = "D"
        self.gun.set(which_gun) 
        playsound("click1.mp3")

# this launches you to window three, the fire select window
    def on_keypress_space(self, evet):
        print("space pressed")
        self.on_button()
        playsound("click1.mp3")
# this quits and closes the window by hitting a single key
    def on_keypress_q(self, evet):
        self.quit()
        playsound("click1.mp3")
# this reloads the game, you have to click it to make it the active window again
    def on_keypress_r(self, evet):
        self.destroy()
        self.__init__()
        playsound("click1.mp3")

#
#
#
#
# this is the third fire screen
class SecondFrame(tk.Toplevel):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.geometry('640x400')
        self.title("Fire status screen")
        tk.Grid.rowconfigure(self, 0, weight=1, uniform='a')
        tk.Grid.columnconfigure(self, 0, weight=1, uniform='a')
        tk.Button(self, text='Close', command=self.destroy).grid(row=0, column=0, sticky="NSEW")
        # These are the bind key definitions
        self.bind("<KeyPress-r>", self.on_keypress_r)
        self.bind("<KeyPress-q>", self.on_keypress_q)
        self.bind("<KeyPress-space>", self.on_keypress_space)
        self.bind("<KeyPress-k>", self.on_keypress_k)


 # this appears to launch the initial window
    def create_splashframe(self):
        splashframe = SplashFrame(self)
        self.withdraw()
        self.wait_window(splashframe)
        self.deiconify()
# this launches the next screen, the fire select screen 
    def on_button(self):
        secondframe = SecondFrame(self)
        self.withdraw()
        self.wait_window(secondframe)
        self.deiconify()



    def kudos(self):
        kudosframe = KudosFrame(self)
        self.withdraw()
        self.wait_window(kudosframe)
        self.deiconify()


    def on_keypress_k(self, evet):
        print("k pressed")
        self.kudos()
        playsound("click1.mp3")
# this reloads the game, you have to click it to make it the active window again
    def on_keypress_r(self, evet):
        self.destroy()
        self.create_splashframe 
        playsound("click1.mp3")
# this launches you to window three, the fire select window
    def on_keypress_space(self, evet):
        print("space pressed")
        self.on_button()
        playsound("click1.mp3")
# this quits and closes the window by hitting a single key
    def on_keypress_q(self, evet):
        self.destroy()
        self.quit()
        playsound("click1.mp3")





#
#
# End fire menu class and related functions
#
#
#Begin secret credits(kudos) screen
#
#

class KudosFrame(tk.Toplevel):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.geometry('640x400')
        self.title("Secret credits screen")
        tk.Grid.rowconfigure(self, 0, weight=1, uniform='a')
        tk.Grid.columnconfigure(self, 0, weight=1, uniform='a')
        tk.Grid.rowconfigure(self, 1, weight=1, uniform='a')
        tk.Grid.columnconfigure(self, 1, weight=1, uniform='a')

        r0c0 = tk.Button(self, text='Close', command=self.destroy, bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        r0c0.grid(row=0, column=0, sticky="NSEW")
        r1c0 = tk.Label(self, text ='Alienslegacy.com Credits \n knoxvilles_joker aka gabriel vos new script  \n martinr1000 font and some coding help \n MLR 2007 for original flash script \n Facebook.com  theuscm \n youtube.com/channel/UC4KYYScA5WcdCZeiU6lcjdA \n cobra_shipwreck channel aka knoxvilles_joker', bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        r1c0.grid(row=1, column=0, sticky="NSEW")
        r1c1 = tk.Label(self, text =' ', bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        r1c1.grid(row=1, column=1, sticky="NSEW")
        r0c1 = tk.Label(self, text ='Python-forum.io credits \n Yoriz coding pointers and help \n ndc85430 coding critique \n ', bg='black', fg='yellow',highlightbackground='yellow', highlightcolor='black', activebackground='yellow')
        r0c1.grid(row=0, column=1, sticky="NSEW")

        # These are the bind key definitions

        self.bind("<KeyPress-r>", self.on_keypress_r)

        self.bind("<KeyPress-space>", self.on_keypress_space)
        self.bind("<KeyPress-k>", self.on_keypress_k)
        self.bind("<KeyPress-q>", self.on_keypress_q)

    def on_button(self):
        secondframe = SecondFrame(self)
        self.withdraw()
        self.wait_window(secondframe)
        self.deiconify()
    def kudos(self):
        kudosframe = KudosFrame(self)
        self.withdraw()
        self.wait_window(kudosframe)
        self.deiconify()
    # this appears to launch the initial window
    def create_splashframe(self):
        splashframe = SplashFrame(self)
        self.withdraw()
        self.wait_window(splashframe)
        self.deiconify()


# this reloads the game, you have to click it to make it the active window again
    def on_keypress_r(self, evet):
        self.destroy()
         
        self.create_splashframe # this appears to launch the initial window
        


    def create_splashframe(self):
        splashframe = SplashFrame(self)
        self.withdraw()
        self.wait_window(splashframe)
        self.deiconify()


    def on_keypress_k(self, evet):
        print("k pressed")
        self.kudos()
        playsound("click1.mp3")

# this launches you to window three, the fire select window
    def on_keypress_space(self, evet):
        print("space pressed")
        self.on_button()
        playsound("click1.mp3")
# this quits and closes the window by hitting a single key
    def on_keypress_q(self, evet):
        self.destroy()
        self.quit()
        playsound("click1.mp3")



#
# End secret credits(kudos) screen
#
#
#
# The below two commands run the entire script
#  
tk_app = TkApp()
tk_app.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Turtle. Pointers of the "arrow" direction of the vector. roomONmoon 1 684 Dec-09-2023, 11:49 PM
Last Post: deanhystad
  How to move in entries using the arrow keys by applying the bind and focus? pymn 4 4,722 Apr-06-2022, 04:29 AM
Last Post: pymn

Forum Jump:

User Panel Messages

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