Python Forum
[Tkinter] Getting the Respective Value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Getting the Respective Value
#1
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
Reply
#2
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") 
Reply
#3
(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.
Reply
#4
Quote:Sorry this does not solve my question.
Sorry, this does not say what you want that is different.
Reply
#5
(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.
Reply


Forum Jump:

User Panel Messages

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