Python Forum
Accessing kivy label from Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing kivy label from Python
#1
Hi, I'm trying to access a label in the kv file.  I would like it to be a clock.  

Currently I have the following code:



from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
import time
from kivy.clock import Clock


class test(BoxLayout):
    
    def showClock(self, dt):
         timey = (time.strftime("%H"+":"+"%M"+":"+"%S")),dt
         print(timey[0])
         self.ids.labelID.text = (timey[0])
    event = Clock.schedule_interval(showClock,1)

        


class question(App):
    def build(self):       
        return test()

if __name__ =="__main__":
    question().run()
KV file:


<test>:
    id:test
    
    BoxLayout:
        Label:
            id: labelID
            text:"label"
        Button:
            id: buttonID
            text:"button"
            on_release:test.showClock(1)
If I comment out the event line..  pressing the button changes the label text ok.

Or if I remove the "self", it'll print to the console every second ok.  

However I can't get it to change the label automatically.
It says:
Error:
TypeError: showClock() missing 1 required positional argument: 'dt'
Any help greatly appreciated!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error when running kivy on python janeik 8 2,033 Jun-16-2023, 10:58 PM
Last Post: janeik
  Accessing same python script from multiple computers bigrockcrasher 1 1,687 May-25-2022, 08:35 PM
Last Post: Gribouillis
  Python modules for accessing the configuration of relevant paths Imago 1 1,365 May-07-2022, 07:28 PM
Last Post: Larz60+
  List index out of range error while accessing 2 lists in python K11 2 2,101 Sep-29-2020, 05:24 AM
Last Post: K11
  Accessing IP Cam Audio In Python Haselsmasher 1 5,456 Jul-10-2020, 02:59 AM
Last Post: kiliantics
  Generate RPM package from a Python + Kivy application for an "offline" installation pruvosim 2 2,199 Jun-04-2020, 12:16 PM
Last Post: pruvosim
  Accessing IBM MQ using Python Rajeshs16 6 7,760 Oct-22-2018, 02:39 PM
Last Post: Larz60+
  Accessing nested dictionary values. Plistlib, Python 2.7 williamlombard 32 20,777 Sep-29-2017, 06:46 AM
Last Post: williamlombard
  Accessing files via python gahdzilla 4 5,404 Jul-02-2017, 07:11 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020