質問編集履歴
2
コード変更2の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -105,27 +105,34 @@
|
|
105
105
|
width: self.height*self.image_ratio
|
106
106
|
```
|
107
107
|
|
108
|
-
# コード変更2(
|
108
|
+
# コード変更2(ObjectPropertyパターン)
|
109
109
|
**add_widgetなしの目的は達成**
|
110
|
-
|
110
|
+
一番目的に近いパターンです。
|
111
|
-
|
111
|
+
可能であればObjectPropertyなしでできないかというところです。
|
112
112
|
|
113
113
|
```ここに言語を入力
|
114
114
|
# -*- coding: utf-8 -*-
|
115
115
|
from kivy.app import App
|
116
116
|
from kivy.uix.image import Image
|
117
117
|
from kivy.uix.floatlayout import FloatLayout
|
118
|
+
from kivy.properties import ObjectProperty
|
118
119
|
|
119
120
|
class MainImage(Image):
|
120
121
|
def __init__(self, **kwargs):
|
121
122
|
super(MainImage, self).__init__(**kwargs)
|
122
123
|
|
124
|
+
def set(self,**package):
|
125
|
+
self.source = package["image"]
|
126
|
+
|
123
127
|
class MainFrame(FloatLayout):
|
128
|
+
mainimage = ObjectProperty(None)
|
129
|
+
|
124
130
|
def __init__(self, **kwargs):
|
125
|
-
mainimage = MainImage()
|
126
|
-
mainimage.source = "./ss.png"
|
127
131
|
super(MainFrame, self).__init__(**kwargs)
|
132
|
+
package = {"image": "./ss.png"}
|
133
|
+
self.mainimage.set(**package)
|
128
134
|
|
135
|
+
|
129
136
|
class MainApp(App):
|
130
137
|
def __init__(self, **kwargs):
|
131
138
|
super(MainApp, self).__init__(**kwargs)
|
@@ -134,6 +141,7 @@
|
|
134
141
|
root = MainFrame()
|
135
142
|
return root
|
136
143
|
|
144
|
+
|
137
145
|
if __name__ == '__main__':
|
138
146
|
MainApp().run()
|
139
147
|
|
@@ -141,8 +149,11 @@
|
|
141
149
|
```ここに言語を入力
|
142
150
|
#:kivy 1.10
|
143
151
|
#-*- coding: utf-8 -*-
|
152
|
+
|
144
|
-
<MainFrame>:
|
153
|
+
<MainFrame>:
|
154
|
+
mainimage:image1
|
145
155
|
MainImage:
|
156
|
+
id:image1
|
146
157
|
<Image>:
|
147
158
|
allow_stretch:True
|
148
159
|
keep_ratio: True
|
1
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -122,7 +122,8 @@
|
|
122
122
|
|
123
123
|
class MainFrame(FloatLayout):
|
124
124
|
def __init__(self, **kwargs):
|
125
|
+
mainimage = MainImage()
|
125
|
-
|
126
|
+
mainimage.source = "./ss.png"
|
126
127
|
super(MainFrame, self).__init__(**kwargs)
|
127
128
|
|
128
129
|
class MainApp(App):
|