Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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()
Comment

PREVIOUS NEXT
Code Example
Python :: python wait until 
Python :: decode base64 with python 
Python :: pythondatetime cheatsheet 
Python :: python check variable is tuple 
Python :: load static files in django 
Python :: python game over screen 
Python :: replace url with text python 
Python :: create a vector of zeros in r 
Python :: how to take second largest value in pandas 
Python :: two input number sum in python 
Python :: python exceute 60 records per minute counter 
Python :: unpack tuple python 
Python :: internet explorer selenium 
Python :: pandas fill missing values with average 
Python :: lda scikit learn 
Python :: how to insert a variable into a string without breaking up the string in python 
Python :: python writing to csv file 
Python :: pandas where based another column 
Python :: how to run a function in interval in python 
Python :: get values using iloc 
Python :: normalize rows in matrix numpy 
Python :: python filter a dictionary 
Python :: how to open csv file in python 
Python :: multiply column of dataframe by number 
Python :: python tkinter treeview get selected item 
Python :: flask debug 
Python :: python set symmetric difference 
Python :: __name__== __main__ in python 
Python :: raise an APi error on django rest view 
Python :: check numpy arrays equal 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =