Python Forum
[Tkinter] problem with refresh UI in tkinter app
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] problem with refresh UI in tkinter app
#6
Tried to tidy this up a little now and yes too many Mydata, that me thinking I can solve the issue with the classes lol.

I still load it at the beginning for it to get last session and the other place I use it is to reset the list when changes are made to then save to the pkl file

Still doesnt update my user page so Im just not getting this class mularky, its like trying to talk to a guy in another building and we have no wifi connection

import tkinter as tk                # python 3
from tkinter import font  as tkfont # python 3
import pickle
 
#on app open load previous pickle file data (this loads all my previous settings)
def loaddata():
    with open('sender2_ini.pkl', 'rb') as f:
        Mydata = pickle.load(f)
        return Mydata
 
Mydata = loaddata()

 
class MainApp(tk.Tk):
 
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.title('Userpage')
 
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
 
        self.frames = {}
        for F in (Userpage, Setup):
            page_name = F.__name__
            frame = F(parent=container, controller=self)
            self.frames[page_name] = frame
 
            # put all of the pages in the same location; the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")
 
        self.show_frame("Userpage")
 
    def show_frame(self, page_name):
        '''Show a frame for the given page name'''
        frame = self.frames[page_name]
        frame.tkraise()
 
    def capture_asset(self):
        print("get the name of button pressed and store global variable for later use")
 
class Userpage(tk.Frame):
 
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent, background="#b22222")
        self.controller = controller

        data1 = tk.StringVar(value=Mydata[0])
        data2 = tk.StringVar(value=Mydata[1])
 
        button1 = tk.Button(self, textvariable =data1, width=8)
        button1.grid(row=2, column=1, padx =5, pady =5)
        button2 = tk.Button(self, textvariable = data2, width=8)
        button2.grid(row=2, column=2, padx =5, pady =5)
        button3 = tk.Button(self, text="Setup", command=lambda: controller.show_frame("Setup"))
        button3.grid(row=6, column=3)
 
class Setup(tk.Frame):
 
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent, width=500, height=500, background="bisque")
        self.controller = controller
 
        data1 = tk.Entry(self, textvariable = tk.StringVar(value=self.Mydata[0]))
        data1.grid(row=4, column=0)
        data2 = tk.Entry(self, textvariable = tk.StringVar(value=self.Mydata[1]))
        data2.grid(row=4, column=1)
 
        def setup_update():
            Mydata = [data1.get(), data2.get()]
            with open('sender2_ini.pkl', 'wb') as f:
                pickle.dump(Mydata, f)
 
        SaveButton = tk.Button(self, text='Save', width=25, command = setup_update)
        SaveButton.grid(row=5, column=0)
 
        senderbutton = tk.Button(self, text="Back to Userpage", command=lambda: controller.show_frame("Userpage"))
        senderbutton.grid(row=8, column=0)
 
if __name__ == "__main__":
    app = MainApp()
    app.mainloop()
Reply


Messages In This Thread
problem with refresh UI in tkinter app - by Philbot - Feb-06-2018, 02:55 AM
RE: problem with refresh UI in tkinter app - by Philbot - Feb-06-2018, 01:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - update/refresh treeview snakes 5 21,016 Dec-02-2023, 07:05 PM
Last Post: aynous19
  [PyQt] Refresh x-labels in matplotlib animation widget JohnT 5 3,786 Apr-23-2021, 07:40 PM
Last Post: JohnT
  Python3 tkinter radiobutton problem Nick_tkinter 14 6,084 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  tkinter python button position problem Nick_tkinter 3 3,581 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  [Tkinter] ClockIn/Out tkinter problem Maryan 2 2,229 Oct-12-2020, 03:42 AM
Last Post: joe_momma
  tkinter| listbox.insert problem Maryan 3 3,539 Sep-29-2020, 05:34 PM
Last Post: Yoriz
  Tkinter problem DPaul 6 4,172 May-28-2020, 03:40 PM
Last Post: DPaul
  [Tkinter] Tkinter - I have problem after import varaible or function from aGUI to script johnjh 2 2,609 Apr-17-2020, 08:12 PM
Last Post: johnjh
  [Tkinter] Problem with tkinter when creating .exe file Jan_97 2 4,622 Feb-27-2020, 05:17 PM
Last Post: Jan_97
  [Tkinter] Tkinter problem catlessness 1 2,068 Jan-15-2020, 05:17 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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