【发布时间】:2016-11-15 10:07:06
【问题描述】:
我正在尝试将ComicCreator GUI 示例的模板实现为我自己项目的模板。 code 很容易理解,但我想将 toolbox.kv 更改为如下所示:
问:我怎样才能附加一个徽标,而不是当前那里的按钮,并且还永久显示当前日期时间显示 (DD/MM/YYYY HH:MM)。最后添加一个字符串NYC, New York, USA,如图所示。
【问题讨论】:
标签: python kivy kivy-language
我正在尝试将ComicCreator GUI 示例的模板实现为我自己项目的模板。 code 很容易理解,但我想将 toolbox.kv 更改为如下所示:
问:我怎样才能附加一个徽标,而不是当前那里的按钮,并且还永久显示当前日期时间显示 (DD/MM/YYYY HH:MM)。最后添加一个字符串NYC, New York, USA,如图所示。
【问题讨论】:
标签: python kivy kivy-language
如果您的图片来自网络,则可以使用 BoxLayout 和 Image 或 AsyncImage。
所以python代码可能是这样的。
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.clock import Clock
import time
class MyLayout(BoxLayout):
your_time = StringProperty()
def __init__(self,**kwargs):
super(MyLayout,self).__init__(**kwargs)
self.orientation = "vertical"
self.padding = 10
Clock.schedule_interval(self.set_time, 0.1)
def set_time(self,dt):
self.your_time = time.strftime("%m/%d/%Y %H:%M")
class MyApp(App):
def build(self):
return MyLayout()
if __name__ == "__main__":
MyApp().run()
而kv文件看起来是这样的。
#:kivy 1.9.1
<MyLayout>:
BoxLayout:
spacing: 10
padding: 10,10,10,0
orientation: "horizontal"
BoxLayout:
orientation: "vertical"
size_hint: 0.3,1
canvas:
Rectangle:
pos: self.pos
size: self.size
AsyncImage
source: 'http://lmsotfy.com/so.png'
Label:
size_hint: 1,0.3
text: root.your_time
color: [0,0,0,1]
Label:
size_hint: 1,0.3
text: "NYC, New York, USA"
color: [0,0,0,1]
Button:
text: ""
BoxLayout:
padding: 10,10,10,0
spacing: 10
size_hint: 1,0.3
orientation: "horizontal"
Button:
text: "Clear"
Button:
text: "Remove"
Button:
text: "Group"
Button:
text: "Color"
Button:
text: "Gestures"
BoxLayout:
padding: 10,10,10,10
size_hint: 1,0.3
Button:
text: "Total figures: 1 Kivy Started"
这将如下所示:
【讨论】: