2017-03-28 2 views
0

AutocompleteEntryで選択された変数を別のフォームまたはクラスの別の関数(つまりfunc2)に渡したいとします。 のinitを()(与えられた3)2つの引数を正確にとります。それはTypeError例外としてエラーを与えているPython Tkinterの別のクラスの関数に変数値またはリストボックスの値を渡す方法

import Tkinter, tkFileDialog, Tkconstants , os 
from Tkinter import * 
import tkMessageBox as 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'] 

# My frame for 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) 
       for 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 it to Demo3 as an 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 for 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) 

に従うように私は試してみました。あなたはのinit関数に別の変数を追加し、値が渡されないとき

# My frame for form 
class simpleform_ap(Tk): 
    def __init__(self,parent, entered_value=None): 
     Tk.__init__(self,parent) 
     .. 
     .. 

はまた、あなたが親としてメソッドやクラスを渡したいん誰にも負けない、それを設定することができ、私に

+0

を通過したいことがあります。 – timgeb

答えて

1

を助けてくださいライン

self.app = simpleform_ap(self.selection, enterednumber) # Send it to Demo3 as an argument 

であなただけの私は、エラーがより多くを言う賭け自己の代わりに、self.selection