The goal is to pass the variable string1 from class Display
to be used in another Tkinter window. So when the button named Next [in class Display
load function] is clicked, it would open a new Tkinter window. And in the new window, the variable string1 from class Display
needs to be retrieved for further action. May i know should i create another class Display2, or should i just add a method in the class Display? Just not sure if it's how it's done. Any pointer would be appreciated.
Currently the string variable can be passed as reference from class Display
to the class Action_Data
. But how can it be passed to another Tkinter window? Many thanks
from tkinter import * import tkinter as tk #Application window root = tk.Tk() #Display Class class Display (tk.Frame): def __init__(self, master, display_data): tk.Frame.__init__(self,master) self.master = master master.title("Display") #passing data as reference self.display= display_data #button self.load_button = tk.Button(self, text="Load", command=self.load) self.load_button.pack() def load(self): #get value pathlabel2.config(text=files[0]) string1=files[0] self.display.action1(string1) self.acition_button = tk.Button(self, text="Next", command=self.new_window) self.acition_button.pack()
Action_Data Class which its variable path1 for clean_inpsection method need the value from display class's load method variable [string1]
#Action_Data Class class Action_Data(tk.Frame): def __init__(self, master): tk.Frame.__init__(self,master) def action1(self, path1): df = pd.read_csv(path1, dtype=str,nrows=999999) .....
#Object instantiate
display= Action_Data(root) display.pack() reader = Display(root, display) reader.pack() pathlabel2 = Label(root) root.mainloop()
https://stackoverflow.com/questions/65527158/how-to-get-variable-from-a-class-to-another-tkinter-window January 01, 2021 at 11:44AM
没有评论:
发表评论