Horje
python get name of tkinter frame Code Example
python get name of tkinter frame
# 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()




Python

Related
typingclub hack python Code Example typingclub hack python Code Example
python return right operand if left is falsy Code Example python return right operand if left is falsy Code Example
Browse Python Code Examples Browse Python Code Examples
count words python Code Example count words python Code Example
override the text in buttons django admin Code Example override the text in buttons django admin Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
6