I want to print the label text (element of FunctionResults
when it is clicked).
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