473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to update Label "e1" ?

I wrote a code and wanna update the PATHNAME for E1.
The Print show's that the Pathname is updating,
but the LabelField is not updating.
What i am doing wrong ?


Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/python
  3. # -*- coding: utf-8 -*-
  4. # http://zetcode.com/gui/tkinter/layout/
  5. # http://docs.activestate.com/komodo/3.5/komodo-doc-guibuilder.html
  6. # http://sebsauvage.net/python/gui/
  7.  
  8.  
  9. from Tkinter import *
  10. from tkMessageBox import *
  11. from tkFileDialog import *
  12. from ttk import *
  13.  
  14. global pathname
  15. pathname ="pathnamevariabl"
  16.  
  17. import os
  18.  
  19. def answer():
  20.     showerror("Answer", "Sorry, no answer available")
  21.  
  22. def CloseButtonClass():
  23.         quit()
  24.  
  25. def BrowseButtonClass():
  26.     name = askopenfilename()
  27.  
  28.     global pathname
  29.  
  30.     pathname = os.path.split(name)[0]
  31.  
  32.     print pathname
  33.  
  34.  
  35. #    versuch nach dem browser das script zu starten mit dem parameter des folders
  36. #    os.system('upload_with_authentication.py pathname')
  37.  
  38.  
  39. def HelpButtonClass():
  40.     showwarning('Help', 'Not yet implemented')
  41.  
  42. def GoButtonClass():
  43.     showwarning('Go', 'Not yet implemented')
  44.  
  45. class MapillaryGui(Frame):
  46.  
  47.     def __init__(self, parent):
  48.         Frame.__init__(self, parent)   
  49.  
  50.         self.parent = parent
  51.  
  52.         self.initUI()
  53.  
  54.     def initUI(self):
  55.  
  56.         self.parent.title("Mapillary Upload GUI")
  57.         self.style = Style()
  58.         self.style.theme_use("default")
  59.         self.pack(fill=BOTH, expand=1)
  60.  
  61.         self.columnconfigure(1, weight=1)
  62.         self.columnconfigure(3, pad=7)
  63.         self.rowconfigure(3, weight=1)
  64.         self.rowconfigure(5, pad=7)
  65.  
  66.         lbl = Label(self, text="Folder")
  67.         lbl.grid(sticky=W, pady=4, padx=5)
  68.  
  69.  
  70.         #das weisse Feld  - old code
  71.         #area = Text(self)
  72.  
  73.         area = Text(self)
  74.  
  75.         Label(area, text="Threat 1 : ").grid(row=0)
  76.         Label(area, text="Threat 2 : ").grid(row=1)
  77.  
  78.         e1 = Entry(area)
  79.         e2 = Entry(area)
  80.  
  81.         e1.grid(row=0, column=1)
  82.         e2.grid(row=1, column=1)
  83.  
  84.         e1.insert(10,pathname)
  85.  
  86.         area.grid(row=1, column=0, columnspan=2, rowspan=4, 
  87.             padx=5, sticky=E+W+S+N)
  88.  
  89.  
  90.         # Button Browse
  91.         abtn = Button(self, text="Browse", command=BrowseButtonClass)
  92.         abtn.grid(row=1, column=3)
  93.  
  94.         #Button Close
  95.         cbtn = Button(self, text="Close", command=CloseButtonClass)
  96.         cbtn.grid(row=2, column=3, pady=4)
  97.  
  98.         #Button Help
  99.         hbtn = Button(self, text="Help", command=HelpButtonClass)
  100.         hbtn.grid(row=5, column=0, padx=5)
  101.  
  102.         #Button Go
  103.         obtn = Button(self, text="GO", command=GoButtonClass)
  104.         obtn.grid(row=5, column=3)
  105.  
  106.  
  107. def main():
  108.  
  109.     root = Tk()
  110.     root.geometry("300x200+300+300")
  111.     app = MapillaryGui(root)
  112.     root.mainloop()
  113.  
  114.  
  115. if __name__ == '__main__':
  116.     main()
  117.  
Jul 16 '15 #1

✓ answered by bvdet

One way is to create a StringVar and assign it to the entry field textvariable option. Use the StringVar object's method set to assign a value. Use a lambda in the browse button command assignment so you can pass the StringVar as an argument for reassignment. You should not need a global variable.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/python
  3. # -*- coding: utf-8 -*-
  4. # http://zetcode.com/gui/tkinter/layout/
  5. # http://docs.activestate.com/komodo/3.5/komodo-doc-guibuilder.html
  6. # http://sebsauvage.net/python/gui/
  7.  
  8. from Tkinter import *
  9. from tkMessageBox import *
  10. from tkFileDialog import *
  11. from ttk import *
  12.  
  13. global pathname
  14. pathname ="pathnamevariabl"
  15.  
  16. import os
  17.  
  18. def answer():
  19.     showerror("Answer", "Sorry, no answer available")
  20.  
  21. def CloseButtonClass():
  22.         quit()
  23.  
  24. def BrowseButtonClass(var):
  25.     name = askopenfilename()
  26.     global pathname
  27.     pathname = os.path.split(name)[0]
  28.     print pathname
  29.     var.set(pathname)
  30.  
  31.  
  32. #    versuch nach dem browser das script zu starten mit dem parameter des folders
  33. #    os.system('upload_with_authentication.py pathname')
  34.  
  35.  
  36. def HelpButtonClass():
  37.     showwarning('Help', 'Not yet implemented')
  38.  
  39. def GoButtonClass():
  40.     showwarning('Go', 'Not yet implemented')
  41.  
  42. class MapillaryGui(Frame):
  43.  
  44.     def __init__(self, parent):
  45.         Frame.__init__(self, parent)   
  46.  
  47.         self.parent = parent
  48.  
  49.         self.initUI()
  50.  
  51.     def initUI(self):
  52.  
  53.         self.parent.title("Mapillary Upload GUI")
  54.         self.style = Style()
  55.         self.style.theme_use("default")
  56.         self.pack(fill=BOTH, expand=1)
  57.  
  58.         self.columnconfigure(1, weight=1)
  59.         self.columnconfigure(3, pad=7)
  60.         self.rowconfigure(3, weight=1)
  61.         self.rowconfigure(5, pad=7)
  62.  
  63.         lbl = Label(self, text="Folder")
  64.         lbl.grid(sticky=W, pady=4, padx=5)
  65.  
  66.  
  67.         #das weisse Feld  - old code
  68.         #area = Text(self)
  69.  
  70.         area = Text(self)
  71.  
  72.         Label(area, text="Threat 1 : ").grid(row=0)
  73.         Label(area, text="Threat 2 : ").grid(row=1)
  74.  
  75.         value = StringVar()
  76.         value.set(pathname)
  77.         e1 = Entry(area, textvariable=value)
  78.         e2 = Entry(area)
  79.  
  80.         e1.grid(row=0, column=1)
  81.         e2.grid(row=1, column=1)
  82.  
  83.         e1.insert(10,pathname)
  84.  
  85.         area.grid(row=1, column=0, columnspan=2, rowspan=4, 
  86.             padx=5, sticky=E+W+S+N)
  87.  
  88.         # Button Browse
  89.         abtn = Button(self, text="Browse", command=lambda:BrowseButtonClass(value))
  90.         abtn.grid(row=1, column=3)
  91.  
  92.         #Button Close
  93.         cbtn = Button(self, text="Close", command=CloseButtonClass)
  94.         cbtn.grid(row=2, column=3, pady=4)
  95.  
  96.         #Button Help
  97.         hbtn = Button(self, text="Help", command=HelpButtonClass)
  98.         hbtn.grid(row=5, column=0, padx=5)
  99.  
  100.         #Button Go
  101.         obtn = Button(self, text="GO", command=GoButtonClass)
  102.         obtn.grid(row=5, column=3)
  103.  
  104.  
  105. def main():
  106.  
  107.     root = Tk()
  108.     root.geometry("300x200+300+300")
  109.     app = MapillaryGui(root)
  110.     root.mainloop()
  111.  
  112.  
  113. if __name__ == '__main__':
  114.     main()
  115.  

2 1741
bvdet
2,851 Expert Mod 2GB
One way is to create a StringVar and assign it to the entry field textvariable option. Use the StringVar object's method set to assign a value. Use a lambda in the browse button command assignment so you can pass the StringVar as an argument for reassignment. You should not need a global variable.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/python
  3. # -*- coding: utf-8 -*-
  4. # http://zetcode.com/gui/tkinter/layout/
  5. # http://docs.activestate.com/komodo/3.5/komodo-doc-guibuilder.html
  6. # http://sebsauvage.net/python/gui/
  7.  
  8. from Tkinter import *
  9. from tkMessageBox import *
  10. from tkFileDialog import *
  11. from ttk import *
  12.  
  13. global pathname
  14. pathname ="pathnamevariabl"
  15.  
  16. import os
  17.  
  18. def answer():
  19.     showerror("Answer", "Sorry, no answer available")
  20.  
  21. def CloseButtonClass():
  22.         quit()
  23.  
  24. def BrowseButtonClass(var):
  25.     name = askopenfilename()
  26.     global pathname
  27.     pathname = os.path.split(name)[0]
  28.     print pathname
  29.     var.set(pathname)
  30.  
  31.  
  32. #    versuch nach dem browser das script zu starten mit dem parameter des folders
  33. #    os.system('upload_with_authentication.py pathname')
  34.  
  35.  
  36. def HelpButtonClass():
  37.     showwarning('Help', 'Not yet implemented')
  38.  
  39. def GoButtonClass():
  40.     showwarning('Go', 'Not yet implemented')
  41.  
  42. class MapillaryGui(Frame):
  43.  
  44.     def __init__(self, parent):
  45.         Frame.__init__(self, parent)   
  46.  
  47.         self.parent = parent
  48.  
  49.         self.initUI()
  50.  
  51.     def initUI(self):
  52.  
  53.         self.parent.title("Mapillary Upload GUI")
  54.         self.style = Style()
  55.         self.style.theme_use("default")
  56.         self.pack(fill=BOTH, expand=1)
  57.  
  58.         self.columnconfigure(1, weight=1)
  59.         self.columnconfigure(3, pad=7)
  60.         self.rowconfigure(3, weight=1)
  61.         self.rowconfigure(5, pad=7)
  62.  
  63.         lbl = Label(self, text="Folder")
  64.         lbl.grid(sticky=W, pady=4, padx=5)
  65.  
  66.  
  67.         #das weisse Feld  - old code
  68.         #area = Text(self)
  69.  
  70.         area = Text(self)
  71.  
  72.         Label(area, text="Threat 1 : ").grid(row=0)
  73.         Label(area, text="Threat 2 : ").grid(row=1)
  74.  
  75.         value = StringVar()
  76.         value.set(pathname)
  77.         e1 = Entry(area, textvariable=value)
  78.         e2 = Entry(area)
  79.  
  80.         e1.grid(row=0, column=1)
  81.         e2.grid(row=1, column=1)
  82.  
  83.         e1.insert(10,pathname)
  84.  
  85.         area.grid(row=1, column=0, columnspan=2, rowspan=4, 
  86.             padx=5, sticky=E+W+S+N)
  87.  
  88.         # Button Browse
  89.         abtn = Button(self, text="Browse", command=lambda:BrowseButtonClass(value))
  90.         abtn.grid(row=1, column=3)
  91.  
  92.         #Button Close
  93.         cbtn = Button(self, text="Close", command=CloseButtonClass)
  94.         cbtn.grid(row=2, column=3, pady=4)
  95.  
  96.         #Button Help
  97.         hbtn = Button(self, text="Help", command=HelpButtonClass)
  98.         hbtn.grid(row=5, column=0, padx=5)
  99.  
  100.         #Button Go
  101.         obtn = Button(self, text="GO", command=GoButtonClass)
  102.         obtn.grid(row=5, column=3)
  103.  
  104.  
  105. def main():
  106.  
  107.     root = Tk()
  108.     root.geometry("300x200+300+300")
  109.     app = MapillaryGui(root)
  110.     root.mainloop()
  111.  
  112.  
  113. if __name__ == '__main__':
  114.     main()
  115.  
Jul 16 '15 #2
great work .. thanx.. that was helping
Jul 22 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: codecraig | last post by:
Hi, I am using Tkinter and I have a Label and a Scale. I want to update my label everytime the Scale value changes. What is the best way of doing this? Do i have to bind for every event type? ...
3
by: kaiser | last post by:
Hello, Am new to C# and am playing around trying to get a while loop to display a int on a windows console using label. private void btnGo_Click(object sender, System.EventArgs e) { int Counter...
5
by: David-L. Nadeau | last post by:
Hi ! I have a little problem. I have a process that runs when a user click a button. The process is long to execute (+/- 5 minutes). So, I put a progress bar and now I want to show the evolution...
3
by: Mike Johnson | last post by:
Thanks for the quick responses. I'm having trouble understanding. I've included the code I using. perhaps someone can tell me what I'm doing wrong. My original question was, I'm new to VB.Net...
7
by: Hexman | last post by:
In my program I have several labels that I want to update with information that is being processed in a calculation module. I have code similar to the following in my module. As it goes through...
4
by: Ryan | last post by:
I've got a little bit of code that runs when you enter data in a datasheet view (which is a subform of the form you are in) if rst!DateReceived >= 30 Then Forms!DisposalRecords.Label90.Caption =...
1
by: yoavkarmon | last post by:
private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e) { Label labeli = new Label; for (int i = 0; i < 2; i++) { ...
4
by: dipak000 | last post by:
Hi, I have a non form class. I want to update label/ check status of check box etc.. in non form class ( here resides functions that contains logic). How can i do that ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.