Python Forum
[Tkinter] Label doesn't refresh
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Label doesn't refresh
#6
(Jul-11-2018, 07:55 AM)Larz60+ Wrote: It doesn't have to be in __init__.
This is a habit of mine as I tend to access from several methods, but it can be used in local scope.

No, it doesn't work in local scope.
I moved it to local scope as the code below and you can try.
You'll find the label doesn't refresh correctly if changing the directory path from a long one to short.

import tkinter
import tkinter.filedialog
import os
 
 
class fileData:
 
     def __init__(self):
          self.targetDir = "./"
          self.mainWin = tkinter.Tk()
 
     def reportShow(self):          
 
          ln1 = 2
          absPathv = tkinter.StringVar()
          tkinter.Label(self.mainWin, text = "     Target   ",justify = tkinter.LEFT).grid(row = ln1, column =0)
          absPath = os.path.abspath(self.targetDir)
          if len(absPath) > 40:  absPath = ' ...%s' % absPath[-37:]
          absPathv.set(absPath)
          tkinter.Label(self.mainWin, textvariable = absPathv, background='white').grid(row = ln1, column = 1, columnspan = 3)                    
 
 
def chooseFolder():                                                   #This is where we lauch the directory change bar
     filesData.targetDir = tkinter.filedialog.askdirectory(title = "Choose the target directory", initialdir=filesData.targetDir)
     filesData.reportShow()
      
  
      
def showMain():
     mainWin = filesData.mainWin
      
     winSize = 360     
     mainWin.geometry('%dx%d+%d+%d' % (winSize, winSize, (mainWin.winfo_screenwidth()-winSize)/2,
                    (mainWin.winfo_screenheight()-winSize)/2))        #The size and position of the main window
     mainWin.minsize(winSize,winSize)
     mainWin.bind('<Control-o>',lambda event: chooseFolder())
 
     filesData.reportShow()
     mainWin.mainloop()
 
 
filesData = fileData()
 
 
if __name__=="__main__":
    showMain()
Reply


Messages In This Thread
Label doesn't refresh - by jollydragon - Jul-10-2018, 09:35 AM
RE: Label doesn't refresh - by Axel_Erfurt - Jul-10-2018, 10:41 AM
RE: Label doesn't refresh - by jollydragon - Jul-11-2018, 03:18 AM
RE: Label doesn't refresh - by Larz60+ - Jul-10-2018, 02:01 PM
RE: Label doesn't refresh - by Larz60+ - Jul-11-2018, 07:55 AM
RE: Label doesn't refresh - by jollydragon - Jul-12-2018, 07:23 AM
RE: Label doesn't refresh - by Larz60+ - Jul-12-2018, 12:21 PM
RE: Label doesn't refresh - by jollydragon - Jul-13-2018, 05:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - update/refresh treeview snakes 5 21,705 Dec-02-2023, 07:05 PM
Last Post: aynous19
  [PyQt] Refresh x-labels in matplotlib animation widget JohnT 5 4,010 Apr-23-2021, 07:40 PM
Last Post: JohnT
  Refresh image in label after every 1s using simple function jenkins43 1 5,558 Jul-28-2019, 02:49 PM
Last Post: Larz60+
  Unable to update or refresh label text in tkinter jenkins43 3 6,863 Jul-24-2019, 02:09 PM
Last Post: Friend
  Tkinter refresh eduardoforo 4 12,723 Nov-14-2018, 09:35 PM
Last Post: woooee
  [PyQt] enviremont refresh duende 2 3,522 May-13-2018, 09:49 AM
Last Post: duende
  pyqt main window refresh poblems duende 0 5,493 Apr-13-2018, 05:05 PM
Last Post: duende
  Refresh test in urwid.Text Stensborg 1 4,638 Mar-05-2018, 11:23 AM
Last Post: Stensborg
  [Tkinter] problem with refresh UI in tkinter app Philbot 5 11,120 Feb-06-2018, 01:10 PM
Last Post: Philbot
  How Can I Do Refresh Window? satrancali 0 7,178 Feb-03-2018, 07:50 AM
Last Post: satrancali

Forum Jump:

User Panel Messages

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