How To Resolve "invalid Property Name" Error To Make File Chooser With Kivy?
I am new to kivy and am trying to build an application in which I have three tabs: one for loading the image, another for displaying the image and a grayscale version side by side,
Solution 1:
Please refer to the example for details.
Example
main.py
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.properties import ObjectProperty
from PIL import Image
classRootWidget(TabbedPanel):
manager = ObjectProperty(None)
img = ObjectProperty(None)
img3 = ObjectProperty(None)
img4 = ObjectProperty(None)
lab = ObjectProperty(None)
defon_touch_up(self, touch):
ifnot self.img3.collide_point(*touch.pos):
returnTrueelse:
self.lab.text = 'Pos: (%d,%d)' % (touch.x, touch.y)
returnTruedefswitch_to(self, header):
# set the Screen manager to load the appropriate screen# linked to the tab head instead of loading content
self.manager.current = header.screen
# we have to replace the functionality of the original switch_to
self.current_tab.state = "normal"
header.state = 'down'
self._current_tab = header
defselect_to(self, *args):
try:
print(args[1][0])
iw = Image.open(args[1][0])
iw.save('./phase.jpg')
gray = iw.convert('1')
gray.save('./gray_im.jpg')
self.img3.source = './gray_im.jpg'
self.img4.source = './gray_im.jpg'
self.img.source = './phase.jpg'
self.img.reload()
self.img3.reload()
self.img4.reload()
except:
passdefupdate_touch_label(self, label, touch):
label.text = 'Pos:(%d, %d)' % (touch.x, touch.y)
label.texture_update()
label.pos = touch.pos
label.size = label.texture_size[0] + 20, label.texture_size[1] + 20classTestApp(App):
title = 'Screen Widget'defbuild(self):
return RootWidget()
defon_pause(self):
returnTrueif __name__ == '__main__':
TestApp().run()
test.kv
#:kivy 1.10.1<RootWidget>:manager:managerimg:imgimg3:img3img4:img4lab:labdo_default_tab:FalseScreenManager:id:managerScreen:id:sc1name:'Loadimg'FileChooserIconView:canvas.before:Color:rgb:0.5,0.4,0.5Rectangle:pos:self.possize:self.sizeon_selection:root.select_to(*args)Screen:id:sc2name:'Image'FloatLayout:Button:id:labpos_hint: {"right":0.55, 'top':1}
size_hint:.15,0.1RelativeLayout:Image:id:imgon_touch_down:str('Relative:{}'.format(args[1].pos))pos_hint: {"left":1, 'bottom':1}
size_hint:0.5,1allow_stretch:TrueRelativeLayout:Image:id:img3pos_hint: {"right":1, 'bottom':1}
size_hint:0.5,1allow_stretch:TrueScreen:id:sc3name:'Image_'FloatLayout:Image:id:img4keep_data:Truepost:self.possize:self.sizeTabbedPanelHeader:text:sc1.namebackground_color:1,0,0,1screen:sc1.nameTabbedPanelHeader:text:sc2.namebackground_color:1,1,0,1screen:sc2.nameTabbedPanelHeader:text:sc3.namebackground_color:1,0,1,1screen:sc3.name
Post a Comment for "How To Resolve "invalid Property Name" Error To Make File Chooser With Kivy?"