我想从Google电子表格标题中创建一个下拉菜单。虽然分别使用下拉菜单可以从Google电子表格中获取信息,但是当我将两者结合使用时,会出现错误消息。
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from kivy.base import runTouchApp
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('frisbee.json', scope)
client = gspread.authorize(creds)
sh = client.open('Teams')
worksheet_list = sh.worksheets()
wsl = str(worksheet_list).split()
for word in wsl:
if "Worksheet" in word:
wsl.remove(word)
for word in wsl:
if "id" in word:
wsl.remove(word)
for word in wsl:
if "<Worksheet" in word:
wsl.remove(word)
dropdown = DropDown()
for index in range(len(wsl)):
btn = Button(text=wsl[index], size_hint_y=None, height=44)
btn.bind(on_release=lambda btn: dropdown.select(btn.text))
dropdown.add_widget(btn)
mainbutton = Button(text='Teams', size_hint=(None, None))
mainbutton.bind(on_release=dropdown.open)
dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x))
runTouchApp(mainbutton)
预期结果:弹出一个带有下拉菜单的窗口。
实际结果:
[INFO ] [Text ] Provider: sdl2
[CRITICAL] [App ] Unable to get a Window, abort.