Kivy,Python:更新标签on_file_drop

时间:2018-12-13 18:30:18

标签: python label kivy

我正在尝试做一个非常简单的GUI,当将文件拖放到应用程序上时可以更新文本标签。

到目前为止,我已经能够识别出何时删除了文件并在控制台上打印了一条消息。不幸的是,当文件被删除时,我一直试图将标签(带有消息“ Linkin Park”)更新为“ Three Day Grace”,但我还没有做到。

有人可以帮我解决mi问题吗?

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

1 个答案:

答案 0 :(得分:1)

您只需要引用Sub PlatingSheet() Const FPATH As String = "\\in-mmge-file\users\tbever\Desktop\VBA\Plating Sheets\" Dim wbTarget As Workbook, wbSource As Workbook Set wbSource = Workbooks.Open(FPATH & "Copy - 24605_17 QC Results and Notes.xlsx") Set wbTarget = Workbooks.Open(FPATH & "Copy - 1.1Unified_Plating_Template.xlsx") With wbSource.Sheets(1).Range("B5:B96") 'assign the value directly wbTarget.Sheets(1).Range("G4").Resize(.Rows.Count, .Columns.Count).Value = .Value End With End Sub ,以便您可以访问MainLayout。如果您将artistName调整为:

App

我认为它将起作用。