Tuesday, 15 July 2014

python - return label text when clicked -


I want to print the label text (element of FunctionResults when it is clicked).

Import Importer Open Fonk Class Simplicity (TCTerms): DF __Init __ (self, original): Tycooner. Vaccine.__int.__ (self, parent) self.parent = parents themselves () Self.Result = [] # self.minsize (8000,300) self.geometry ("800x300") def initialization (self ): Self. Grade () self.entryVariable = Tkinter.StringVar () self.entry = Tkinter. Self (., Self Text.) Self. Anti Grid (column = 0, line = 0, stick = = 'ew') self Anti Bind ("return> gt;", auto.onepressinter) EntryVariable.set (u "") self.labelVars = [] Category: Jammu (1,30): labelVar = Tkinter.StringVar () labelVar.set ('') self.labelVars.append (labelVar) label = Tkinter. Label ("Auto, Remote = Label", Anchor = "W", FG = "Black", BG = "White") Labels ("& lt; 1>", Lambda Event, Text = "Some Text" Self.click_link (event, text)) label.grid (column = 0, line = j, column = 2, sticky = 'ew') self.grid_columnconfigure (0, weight = 1) itself. Modem (right, wrong) self .update (self.geometry (self.geometry ()) self.entry.focus_set () self.entry.selection_range (0, Tkinter.END) DEF OnPressEnter (self, event): #FunctionResults Func1 is back by a Func1 self.FunctionResults = Func.Func1 (self.entryVariable.get ()) in the self.FunctionResults = list (reverse (self.Result)) category (0, lane (self.Result)): Print "results", I, ":", self. Function Result [i] Self. Labwares [i] .set (auto. Function result [i]) self.entry.focus_set () self.entry.selection_range (0, Tkinter.END) def click_link (auto, event, text): print "You '% s 'Click on'% text #l ["text"] #OsSystem ("Open" + Textual + ".txt") if __name__ == "__main__": app = SimpleAp_Tyak (none) Appeal ('Mary App' ) Apes. Mileop ()

Instead, I get the , you clicked some text .

How do I type the function click_link (self, event, text): to get the name associated with that click's label?

I have seen some answers using the command , but I do not want to use a single button.

< Div class = "post-text" itemprop = "text">

You can get text from a widget that was clicked like this:

  def click_link (auto, event , Text): "You clicked '% s'"% event.widget ["text"]  

edit full code for me Ubuntu 14.04 and working on OS X 10.10

  Import Tunkeror Import OS class SimpleConnection (TKNeter): def __init __ (self, parent): Tkinter.Tk .__ init __ (self, parent) self.parent = parents self-interlise () self Result = [] # Self. Missise (8000,300) self Starting gemetry ("800x300") def (self): self. Grade () self.entryVariable = Tkinter.StringVar () self.entry = Tkinter.Entry (self, textvariable = self.entryVariable) self.entry.grid (column = 0, line = 0, sticky = 'EW') self. Entry.bind ("Return & gt;", self.OnPressEnter) self.entryVariable.set (u "") self.labelVars = [] J (1,30) in range: LabelVar = Tkinter.StringVar () LabelVar.set ('') labeled self.labelVars.append (labelVar) label = Tkinter.Label (self, textvariable = labelVar, anchor = "w", fg = "black", bg = "white") label. Label: Grid (column = 0, line = j, column = 2, sticky = 'ew'), lambda event, text = "some text": \ self.click_link (event, text) ) Self.grid_columnconfigure (0, weight = 1) Self. Paragmeter (right, wrong) auto.update () self Geometry (self geometry) self.entry.focus_set () self.entry.selection_range (0, Tkinter.END) def OnPressEnter (auto, incident): #Result A list self.Result = self.entryVariable.get () In the self.Result = list (reverse (self.Result)) category I (0, lane (self result)): print "results", me, ":", self Results [i] self.labelwars [i] .set (self. Results [i]) self.entry.focus_set () sf.net Section_reeng (0, tikenator.END) def click_link (self, event, text): print "You clicked '% s'"% event.widget ["text"] if __name__ == "__main__": app = Simpleapp_tk (None) app.title ('my application') app.mainloop ()  

No comments:

Post a Comment