Python Forum
[Tkinter] Getting the Respective Value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Getting the Respective Value (/thread-16073.html)



Getting the Respective Value - Vicolas - Feb-13-2019

from tkinter import *
import Pmw

class Message:
    def __init__(self):
        self.root = Tk()
        self.build_Message()
        self.root.mainloop()

    def build_Message(self):
        self.entry = self.combobox =  None
        self.messages = {'Help': 'Save current file',
                         'Userevent': 'Saving file "foo"',
                         'Busy': 'Busy deleting all files from file system ...',
                         'Systemevent': 'File "foo" saved',
                         'Usererror': 'Invalid file name "foo/bar"',
                         'Systemerror': 'Failed to save file: file system full',
                         }
        self.combobox = Pmw.ComboBox(self.root, labelpos=N, label_text='Message Type',
                                dropdown=False,
                                listbox_relief=SUNKEN,
                                listbox_font = 'tahoma 10 bold',
                                scrolledlist_items = self.messages.keys(),
                                selectioncommand = self.enter,
                                listbox_background='grey')
        self.combobox.pack(fill=X,padx=5,pady=5)
        self.entry = Pmw.MessageBar(self.root,labelpos=W,label_text='Status:',entry_width=30)
        self.entry.pack(fill=X,padx=5,pady=5)

    def enter(self,event):
        self.combobox.configure(label_text=event)
        for k,v in self.messages.items():
            self.entry.helpmessage(v)

if __name__=="__main__":
    Message()
Please how can I click on the scrolled list item 'keys' and get the respective 'values' from 'self.message' dictionary variable displayed in my Pmw MessageBar Widget. Thanks


RE: Getting the Respective Value - woooee - Feb-13-2019

Under the enter() function, print the field you name as event, as it should contain the item selected, which should also be the key for the self.messages dictionary.
    def enter(self,event):
        if event in self.messages:
            print(event, self.messages[event])
        else:
            print(event, "Lookup error") 



RE: Getting the Respective Value - Vicolas - Feb-14-2019

(Feb-13-2019, 05:55 PM)woooee Wrote: Under the enter() function, print the field you name as event, as it should contain the item selected, which should also be the key for the self.messages dictionary.
 def enter(self,event): if event in self.messages: print(event, self.messages[event]) else: print(event, "Lookup error") 
Sorry this does not solve my question.
Thanks.


RE: Getting the Respective Value - woooee - Feb-14-2019

Quote:Sorry this does not solve my question.
Sorry, this does not say what you want that is different.


RE: Getting the Respective Value - Vicolas - Feb-15-2019

(Feb-14-2019, 10:15 PM)woooee Wrote:
Quote:Sorry this does not solve my question.
Sorry, this does not say what you want that is different.
Sorry Sir, your code did worked. At first I thought it was something else.
Thanks a lot.