Python Forum

Full Version: Getting the Respective Value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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") 
(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.
Quote:Sorry this does not solve my question.
Sorry, this does not say what you want that is different.
(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.