python - 无法在 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()
解决方案
要调用函数,您应该使用括号:
self.takephoto()
推荐阅读
- android - SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 和 FLAG_TRANSLUCENT_STATUS 已弃用
- javascript - 在 JSON 文件中保存用户 ID 和值
- amazon-web-services - 将附加信息附加到 Lambda 超时消息?
- java - 无字段 sessionHostPortCache - Apache Commons Net 存储文件
- node.js - 如何从nodejs上传文件到firebase存储 - 客户端
- javascript - this.props.value 未定义 React
- python - 排除每周不出现的 ID
- swift - 为什么在 textViewDidBeginEditing 之前调用观察者 onKeyboardDisplayed
- python - 有效地将 DataFrame 行转换为列名和值组合的列表
- reactjs - 反应 ts 类型 'Promise
' 缺少类型 'X' 的以下属性