【发布时间】:2019-05-15 00:54:12
【问题描述】:
我正在尝试做一个非常简单的 GUI,它可以在将文件拖放到应用程序上时更新文本标签。
到目前为止,我已经能够识别何时删除文件并在控制台上打印一条消息。不幸的是,现在我一直在尝试在删除文件时将标签(带有消息“Linkin Park”)更新为“Three Day Grace”,但我还没有做到。
谁能帮我解决我的问题?
main.py
#Se importan archivos necesarios de Kivy
from kivy.app import App
from kivy.config import Config
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window
from kivy.properties import StringProperty
import random
class MainLayout(FloatLayout):
artistName = StringProperty()
def __init__(self, **kwargs):
super(MainLayout, self).__init__(**kwargs)
self.artistName = "Linkin Park"
def _on_file_drop(self):
self.artistName = "Three Day Grace"
print "File Dropped"
class MainApp(App):
def build(self):
self.title = "Shantazam"
Window.bind(on_dropfile=self._on_file_drop)
Window.size = (400,700)
return MainLayout()
def _on_file_drop(self, window, file_path):
file_path = file_path.split("\\")
fileToOpen = file_path[-2]+"\\"+file_path[-1]
print(enter code herefileToOpen)
MainLayout()._on_file_drop()
return
if __name__ == '__main__':
MainApp().run()
MainApp.kv
#:import utils kivy.utils
<MainLayout>:
canvas:
Color:
rgb: utils.get_color_from_hex('#0088ff')
Rectangle:
pos: 0,0
size: self.size
Label:
text: 'Shantazam'
font_size: 72
markup: True
shorten: True
ellipsis_options: {'color':(1,0.5,0.5,1),'underline':True}
size_hint: (1, 0.17)
pos_hint: {'x': 0 , 'y' : 0.7}
Label:
id: label1
text: root.artistName
【问题讨论】: