Kivy Digital Clock Issues

2024/11/15 11:54:44

I'm trying to add a digital clock to my Kivy program, it seems to be having trouble.

Here is the .py:

import kivykivy.require('1.10.0')from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.stacklayout import StackLayout
from kivy.clock import Clock
from kivy.properties import ObjectProperty
from kivy.properties import StringPropertyimport timeclass IntroScreen(Screen):passclass ContScreen(Screen):passclass ScreenManagement(ScreenManager):passbackbone = Builder.load_file("main.kv")class Status(FloatLayout):_change = StringProperty()_tnd = ObjectProperty(None)def update(self, *args):self.time = time.asctime()self._change = str(self.time)self._tnd.text = str(self.time)print (self._change)class XGApp(App):time = StringProperty()def update(self, *args):self.time = str(time.asctime())  # + 'time'?def build (self):Clock.schedule_interval(self.update, 1)return backbonexApp = XGApp()if __name__ == "__main__":xApp.run()

and the .kv

<ContScreen>:FloatLayoutsize_hint: .1,.1canvas.before:Color:rgba: 0,0,0,1Rectangle:pos: self.possize: self.sizeLabel:text: app.time

ContScreen is the title of the screen I want to show the clock on, it's served by a separate Builder (main.kv).

Any help would be appreciated! Been struggling with this clock for a few hours now. The trouble seems to be on the .kv side from what I can tell.

BONUS: If you want to go the extra mile, I also want to add a timer that counts down x amount on press of a button on the .kv. The x amount would be different depending on which button you press.

Answer

I have made a fork of the original kivydigitalclock here. It should be easier to use than the original. You can add it to your .kv file just as any other widget. For example, something like:

<ContScreen>:FloatLayoutsize_hint: .1,.1canvas.before:Color:rgba: 0,0,0,1Rectangle:pos: self.possize: self.sizeLabel:text: app.timeDigitalClock:pos_hint: {'right': 1.0, 'center_y': 0.5}size_hint: (0.2, 0.2)

should work. Note that in your main .py file you will need to include:

from digitalclock.digitalclock import DigitalClock

(assuming that the digitalclock.py file is in a digitalclock folder)

https://en.xdnf.cn/q/119421.html

Related Q&A

Read a file name and create a column with it [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 4…

Python : T test ind looping over columns of df

My dataframe is composed of accounting variables and a dummy variable that allows me to identify two types of company. I would like to perform a t-test for every column of my dataframe in order to comp…

I want to understand which line of code outputs **none** in the function

The last line of the output is none can someone explain why pls def just_lyrics():print ("i am a bad coder")print (" i keep trying to learn everday")def double_lyrics():just_lyrics(…

How to clear python console (i.e. Ctrl+L command line equivalent)

OS = Linux[boris@E7440-DELL ~]$ uname -a Linux E7440-DELL 3.17.4-200.fc20.x86_64 #1 SMP Fri Nov 21 23:26:41 UTC 2014 x86_64 x86_64 x86_64 GNU/LinuxFrom python console (Spyder 2.2.4, Python 2.7.5 64bits…

Floating point accuracy in python

Any reason why c shouldnt equal 0.321?>>> from math import ceil >>> a = 123.321 >>> b = a % 60 >>> b 3.320999999999998 >>> ceil(b) 4.0 >>> c = cei…

datetime64 comparison in dataframes

I am struggling with datetime64 comparisons in dataframes to update a column. lets say we have a dataframe df with a date columndf.date.values[0] Out[128]: numpy.datetime64(2015-05-17T22:00:00.00000000…

Relative import of a apackage in python flask application

Trying to make the sample flask application more modular,I am new to python and flask trying to build a sample application where , I have planned to maintain the folder structure of the application a…

Same sparql not returning same results

Im using the same sparql statement using two different clients but both are not returning the same results. The owl file is in rdf syntax and can be accessed here. This is the sparql statement: PREFIX …

Accessing nested values in nested dictionaries in Python 3.3

Im writing in Python 3.3. I have a set of nested dictionaries (shown below) and am trying to search using a key at the lowest level and return each of the values that correspond to the second level. Pa…

scrape site with anti forgery token

Im trying to scrape data from website that uses anti forgery token what i tried to do is sending a get request then finding the key and use it to send a post request i was able to successfully scrape t…