我想我迷失了解决方案。我不明白如何使用.kv页面使用该函数。我的示例代码如下。问题是,当我点击“好运”按钮时,我收到一个错误,例如“属性错误:'按钮'对象没有属性'app'”我尝试将我的函数行替换为不同的地方,例如在类下,但保持得到不同的错误,我是否错过了明显的东西,或者只是我的整个方式都是错误的?
main.py
# -*- coding: utf8 -*-
from trakt.users import User
import random
import imdb
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
import kivy.app
kivy.require('1.9.1')
moviesDB = imdb.IMDb()
myuser = User(str('lunedor'))
watchlist = myuser.watchlist_movies
def dataget():
global myline
myline = str(random.choice(watchlist))[9:1000]
movies = moviesDB.search_movie(str(myline))
id = movies[0].getID()
global movie
movie = moviesDB.get_movie(id)
global posterurl
posterurl = movie["full-size cover url"]
global title
title = movie['title']
global year
year = movie["year"]
global rating
rating = movie["rating"]
global runtime
runtimes = movie["runtimes"]
runtime = ' '.join(map(str, runtimes))
global directStr
directors = movie["directors"]
directStr = ' '.join(map(str, directors))
global writerStr
writers = movie["writers"]
writerStr = ', '.join(map(str, writers))
global casting
casting = movie["cast"]
global actors
actors = ', '.join(map(str, casting))
global summary
summary = movie["plot outline"]
genres = movie["genres"]
global genre
genre = ', '.join(map(str, genres))
print(movie)
print(id)
posterurl = movie["full-size cover url"]
showline1 = title + "\n" + str(year) + " - " + str(rating) + "\n" + str(runtime) + " minutes" + " - " + genre
showline2 = "Director: " + directStr + "\n" + "\n" + "Writers: " + writerStr
showline3 = "Cast: " + actors
showline4 = "Summary: " + "\n" + str(summary)
class RootWidget(GridLayout):
def __init__(self, **kwargs):
super(RootWidget, self).__init__(**kwargs)
try:
dataget()
except:
print('Error')
dataget()
弑天下
相关分类