我正在尝试制作GUI,我想要这样的时钟: https://github.com/dwalker0044/KivyDigitalClock
我想将其添加到菜单页面,该页面具有可导航至其他页面的按钮,但我无法弄清楚。我导入了文件,但不知道如何将其添加到屏幕。我已经为此困扰了一段时间,所以如果有人可以帮助我。
这是我的代码:
main.py
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'systemanddock')
#KivyTest.py
import kivy
kivy.require('1.0.6') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.properties import ObjectProperty
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
#from cefpython3 import cefpython as cef
from glob import glob
from random import randint
from os.path import join, dirname
from kivy.app import App
from kivy.logger import Logger
from kivy.uix.scatter import Scatter
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
from kivy.uix.scrollview import ScrollView
from kivy.properties import StringProperty
import sys
import platform
import webbrowser
import random
import os
import time
import datetime
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import StringProperty
from kivy.properties import NumericProperty
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics import *
from digitalclock import DigitalClock
from digitalclock import SecondsIndicator
class Face(Screen):
pass
class Menu(Screen):
def open_Browser(self):
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
cef.CreateBrowserSync(url="https://www.google.com/",
window_title="Google")
cef.MessageLoop()
cef.Shutdown()
def open_YouTube(self):
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
cef.CreateBrowserSync(url="https://www.youtube.com/",
window_title="YouTube")
cef.MessageLoop()
cef.Shutdown()
def open_Pictures(self):
picturesApp = PicturesApp()
picturesApp.run()
def open_Camera(self):
TestCamera().run()
class Commands(Screen):
pass
class Manager(ScreenManager):
face = ObjectProperty(None)
menu = ObjectProperty(None)
class IonApp(App):
def build(self):
m = ScreenManager(transition = NoTransition())
m.add_widget(DigitalClock(name='Clock'))
return m
if __name__ == '__main__':
IonApp().run()
答案 0 :(得分:0)
add_widget()
的{{1}}方法仅接受ScreenManager
个实例。
尝试将Screen
实例添加到DigitalClock
时,应该会出错。
您需要将ScreenManager
实例添加到您的DigitalClock
对象之一(例如Screen
或Menu
)中,然后将该Commands
添加到您的Screen
使用ScreenManager
。
add_widget()
代码没有准备好包含在其他代码中。假设您已将数字时钟代码放置在KivyDigitalClock
文件夹中(从代码中出现),那么您还需要在代码中进行digitalclock
调用。在您进行Builder.load_file('digitalclock/digitalclock.kv')
通话之前,一个合适的地方。
所以我认为这是可行的:
IonApp().run()