簡體   English   中英

無法在 Python 類中運行定義的函數

[英]Can't run a defined function in a Python class

我正在為 photobooth 制作一個應用程序並測試功能,我在代碼中構建界面后調用了名為 takephoto 的函數,但控制台沒有打印 TESTING。 什么可能導致問題出現?

import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.videoplayer import Video
from kivy.uix.video import Video
from kivy.config import Config
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
import sys
import os
import subprocess
import datetime
import time

class MyPhotoBoothApp(App):
    def build(self):
        self.takephoto
        global fl
        fl = FloatLayout()
        fl = FloatLayout(size=(300, 300))
        global buttonstart
        buttonstart = Button(text=' ', background_color=[0, 0, 0, 0], on_press=self.startcycle)
        fl.add_widget(buttonstart)
        global videostart
        videostart = Video(source='C:/PhotoBooth/animations/Start/TouchHereToStart.mov',  state='play', options={'allow_stretch': False})
        videostart.options = {'eos': 'loop'}
        fl.add_widget(videostart)
        return fl

    def startcycle(self, *arg):

        fl.remove_widget(buttonstart)
        fl.remove_widget(videostart)
        self.countdown = Video(source='C:/PhotoBooth/animations/Countdown/Countdown.mov',  state='play', options={'allow_stretch': False})
        self.countdown.options = {'eos': 'false'}
        fl.add_widget(self.countdown)
        return fl

    def takephoto(self):
        print("TESTING")

Config.set('graphics', 'fullscreen', 'auto')
Config.set('graphics', 'window_state', 'maximized')
Config.set('graphics', 'rotation', 0)
MyPhotoBoothApp().run()

要調用函數,您應該使用括號:

self.takephoto()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM