首页 > 解决方案 > 无法在 Python 类中运行定义的函数

问题描述

我正在为照相亭制作一个应用程序并测试功能,我在代码中构建接口后调用了名为 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()

标签: python

解决方案


要调用函数,您应该使用括号:

self.takephoto()

推荐阅读