Python Holen Sie sich den Namen des Tkinter -Rahmens

# How to get the name of the current Tkinter frame
from tkinter import *

# Directs you to the next frame (moves the selected frame to the top)
def raise_frame(frame):
  frame.tkraise()

# Get the name of the current frame
def get_name(frame):
  print("Default frame name: " + str(frame))
  current_frame = getattr(frame_var, str(frame).replace(".!", ""))
  print("Current frame name: " + current_frame)
  
# Class to define frame variales
class Frame_var:
  frame = "the first frame"
  frame2 = "the second frame"
# Defining class as a veriable
frame_var = Frame_var()

# Setting up the window
root = Tk()
home_frame = Frame(root, bg="black", borderwidth=1, padx=50, pady=10)
other_frame = Frame(root, bg="grey", borderwidth=1, padx=50, pady=10)

for frame in (home_frame, other_frame):
  frame.pack()

raise_frame(home_frame)

# Home frame
Button(home_frame, text='home frame', command=lambda:[raise_frame(other_frame), get_name(home_frame)]).pack()

# Other frame
Button(other_frame, text='other frame', command=lambda:[raise_frame(home_frame), get_name(other_frame)]).pack()

# Main loop
root.mainloop()
Hello There