How to pass variable value or Listbox value into function of another class in Python Tkinter -


i want pass variable selected in autocompleteentry fuinction (i.e func2) in form or class. tried follow

import tkinter, tkfiledialog, tkconstants , os tkinter import * import tkmessagebox messagebox, tkinter import sys import ttk import tkfont list1233 = ['a', 'actions', 'additional', 'also', 'an', 'and', 'angle', 'are', 'as', 'be', 'bind', 'bracket', 'brackets', 'button', 'can', 'cases', 'configure', 'course', 'detail', 'enter', 'event', 'events', 'example', 'field', 'fields', 'for', 'give', 'important', 'in', 'information', 'is', 'it', 'just', 'key', 'keyboard', 'kind', 'leave', 'left', 'like', 'manager', 'many', 'match', 'modifier', 'most', 'of', 'or', 'others', 'out', 'part', 'simplify', 'space', 'specifier', 'specifies', 'string;', 'that', 'the', 'there', 'to', 'type', 'unless', 'use', 'used', 'user', 'various', 'ways', 'we', 'window', 'wish', 'you']  # frame form class simpleform_ap(tk):     def __init__(self,parent):         tk.__init__(self,parent)         self.parent = parent         self.initialize()         self.grid()             def initialize(self):         # dropdown menu         self.dropmenu2 = autocompleteentry(list1233)         self.dropmenu2.grid(row=6, column=3)     def func2(self,value2):         print value2         messagebox.showinfo("filesave status ", valu2) class autocompleteentry(entry):     def __init__(self, list123, *args, **kwargs):                 entry.__init__(self, *args, **kwargs)         self.list123 = list123              self.var = self["textvariable"]         if self.var == '':             self.var = self["textvariable"] = stringvar()         self.var.trace('w', self.changed)         self.bind("<right>", self.selection)         self.bind("<up>", self.up)         self.bind("<down>", self.down)                 self.lb_up = false     def changed(self, name, index, mode):           if self.var.get() == '':             self.lb.destroy()             self.lb_up = false         else:             words = self.comparison()             if words:                             if not self.lb_up:                     self.lb = listbox()                     self.lb.bind("<double-button-1>", self.selection)                     print "satyaaa"                     self.lb.bind("<right>", self.selection)                #     self.lb.bind('<<listboxselect>>', self.functt)                     self.lb.place(x=self.winfo_x(), y=self.winfo_y()+self.winfo_height())                     self.lb_up = true                  self.lb.delete(0, end)                 w in words:                     self.lb.insert(end,w)             else:                 if self.lb_up:                     self.lb.destroy()                     self.lb_up = false     def functt(self,val):         widget = val.widget         selection=widget.curselection()         value = widget.get(selection[0])         print "selection:", selection, ": '%s'" % value         if self.lb_up:             print "i",self.lb.get(active)      def selection(self, event):                 if self.lb_up:                         self.var.set(self.lb.get(active))             print "she", self.lb.get(active)             enterednumber=self.lb.get(active)                         self.lb.destroy()             self.lb_up = false             self.icursor(end)             self.app = simpleform_ap(self.selection, enterednumber)   # send demo3 argument      def up(self, event):         if self.lb_up:             if self.lb.curselection() == ():                 index = '0'             else:                 index = self.lb.curselection()[0]             if index != '0':                                 self.lb.selection_clear(first=index)                 index = str(int(index)-1)                                 self.lb.selection_set(first=index)                 self.lb.activate(index)      def down(self, event):         if self.lb_up:             if self.lb.curselection() == ():                 index = '0'             else:                 index = self.lb.curselection()[0]             if index != end:                                         self.lb.selection_clear(first=index)                 index = str(int(index)+1)                         self.lb.selection_set(first=index)                 self.lb.activate(index)                 #print       def comparison(self):         pattern = re.compile('.*' + self.var.get() + '.*')         return [w w in self.list123 if re.match(pattern, w)]               def create_form(argv):     form = simpleform_ap(none)     w, h = form.winfo_screenwidth(), form.winfo_screenheight()     form.geometry("1000x650")     form.resizable(width=false, height=false)     form.title('meta data exporter')     form.mainloop() if __name__ == "__main__":      global label123      create_form(sys.argv) 

it giving error typeerror: init() takes 2 arguments (3 given). please me

you can add variable init function , set none when no value passed

# frame form class simpleform_ap(tk):     def __init__(self,parent, entered_value=none):         tk.__init__(self,parent)         ..         .. 

also want pass method or class parent in line

self.app = simpleform_ap(self.selection, enterednumber)   # send demo3 argument 

you may want pass self instead of self.selection


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -