prestige

AI_Lab1

Apr 14th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.40 KB | None | 0 0
  1. from Tkinter import *
  2.  
  3. class Computing():
  4.     def object_recognition(self, attributes):
  5.         temp1 = (set(listbox1.get(0, END)) & set(attributes))
  6.         temp2 = (set(listbox3.get(0, END)) & set(attributes))
  7.         if len(temp1) >= len(temp2):
  8.             return '1'
  9.         return '2'
  10.     def recognize_lerning(self, attributes, object_id):
  11.         if object_id == '1':
  12.             #adding features to object2
  13.             temp_list = list((set(attributes) & set(listbox1.get(0, END))) | set(listbox3.get(0, END)))
  14.             listbox3.delete(0, END)
  15.             for x in temp_list:
  16.                 listbox3.insert(END, x)
  17.             #deleting features from object1 that was added to object2
  18.             temp_list = list(set(listbox1.get(0, END)) - (set(attributes) & set(listbox1.get(0, END))))
  19.             listbox1.delete(0, END)
  20.             for x in temp_list:
  21.                 listbox1.insert(END, x)
  22.         if object_id =='2':
  23.             #adding features to object1
  24.             temp_list = list((set(attributes) & set(listbox3.get(0, END))) | set(listbox1.get(0, END)))
  25.             listbox1.delete(0, END)
  26.             for x in temp_list:
  27.                 listbox1.insert(END, x)
  28.             #deleting features from object2 that was added to object1
  29.             temp_list = list(set(listbox3.get(0, END)) - (set(attributes) & set(listbox3.get(0, END))))
  30.             listbox3.delete(0, END)
  31.             for x in temp_list:
  32.                 listbox3.insert(END, x)
  33.     def adding_features(self, attributes, object_id):
  34.         if object_id == '1':
  35.             features_to_add = (set(listbox1.get(0, END)) - set(attributes)) & (set(listbox2.get(0, END)) - set(attributes)) & (set(listbox3.get(0, END)) - set(attributes))
  36.             temp_list = list(set(listbox1.get(0, END)) | features_to_add)
  37.             listbox1.delete(0, END)
  38.             for x in temp_list:
  39.                 listbox1.insert(END, x)
  40.         if object_id == '2':
  41.             features_to_add = (set(listbox1.get(0, END)) - set(attributes)) & (set(listbox2.get(0, END)) - set(attributes)) & (set(listbox3.get(0, END)) - set(attributes))
  42.             temp_list = list(set(listbox3.get(0, END)) | features_to_add)
  43.             listbox3.delete(0, END)
  44.             for x in temp_list:
  45.                 listbox3.insert(END, x)
  46.        
  47. class subform():
  48.     def __init__(self):
  49.         self.subroot = Tk()    
  50.         self.object_attributes = textbox1.get().split(' ')
  51.         self.computer = Computing()
  52.         self.object_id = self.computer.object_recognition(self.object_attributes)
  53.         self.label1_text = 'This is object number ' + self.object_id
  54.         self.label1 = Label(self.subroot, text = self.label1_text)
  55.         self.button1 = Button(self.subroot, text = 'Yes', width = 20, command = lambda : self.button1_click())
  56.         self.button2 = Button(self.subroot, text = 'No', width = 20, command = lambda : self.button2_click())
  57.         self.label1.grid(row = 1, column = 1, columnspan = 2)
  58.         self.button1.grid(row = 2, column = 1)
  59.         self.button2.grid(row = 2, column = 2)
  60.        
  61.     def button1_click(self):
  62.         self.computer.adding_features(self.object_attributes, self.object_id)
  63.         self.subroot.destroy()
  64.     def button2_click(self):
  65.         self.computer.recognize_lerning(self.object_attributes, self.object_id)
  66.         self.subroot.destroy()
  67.        
  68. def button_click():    
  69.     if v2.get() == 1 and v1.get() == 'First':
  70.         for x in textbox1.get().split(' '):
  71.             listbox1.insert(END, x)
  72.         textbox1.delete(0, END)
  73.     elif v2.get() == 1 and v1.get() == 'Second':
  74.         for x in textbox1.get().split(' '):
  75.             listbox3.insert(END, x)
  76.         textbox1.delete(0, END)
  77.     elif v2.get() == 1 and v1.get() == 'General':
  78.         for x in textbox1.get().split(' '):
  79.             listbox2.insert(END, x)
  80.         textbox1.delete(0, END)
  81.     if v2.get() == 2:
  82.         subform1 = subform()
  83.        
  84. def radiobutton2_click():
  85.     temp_list1 = []
  86.     temp_list2 = []
  87.     temp_list3 = []
  88.     temp_list1 = set(listbox1.get(0, END))
  89.     temp_list2 = list(set(listbox1.get(0, END)) & set(listbox3.get(0, END)) | set(listbox2.get(0, END)))
  90.     temp_list3 = set(listbox3.get(0, END))
  91.     listbox1.delete(0, END)
  92.     listbox2.delete(0, END)
  93.     listbox3.delete(0, END)
  94.     for x in temp_list1:
  95.         listbox1.insert(END, x)
  96.     for x in temp_list2:
  97.         listbox2.insert(END, x)
  98.     for x in temp_list3:
  99.         listbox3.insert(END, x)
  100.        
  101. root = Tk()
  102. frame1 = Frame()
  103. frame2 = Frame()
  104. frame3 = Frame()
  105.  
  106. v1 = StringVar()
  107. v1.set('First')
  108. dropdownlist1 = OptionMenu(root, v1,'First', 'Second', 'General')
  109. listbox1 = Listbox()
  110. listbox2 = Listbox()
  111. listbox3 = Listbox()
  112. textbox1 = Entry(width = 45)
  113. button1 = Button(None, text = 'Submit', height = 1, width = 6, command = button_click)
  114.  
  115. v2 = IntVar()
  116. v2.set(0)
  117. radiobutton1 = Radiobutton(text = 'Lerning', variable = v2, value = 1)
  118. radiobutton2 = Radiobutton(text = 'Recognition', variable = v2, value = 2, command = radiobutton2_click)
  119.  
  120. listbox1.grid(row = 1, column = 1)
  121. listbox2.grid(row = 1, column = 2)
  122. listbox3.grid(row = 1, column = 3)
  123. textbox1.grid(row = 2, column = 1, columnspan = 3, sticky = 'w')
  124. radiobutton1.grid(row = 3, column = 1, sticky = 'w')
  125. radiobutton2.grid(row = 3, column = 2, sticky = 'w')
  126. button1.grid(row = 3, column = 3, sticky = 'e')
  127. dropdownlist1.grid(row = 2, column = 3, sticky = 'e')
  128. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment