正如标题所说,每次更改值时,我都会尝试打印出Switch小部件的值.我已设法编写回调本身,但我似乎无法弄清楚在我的.kv文件中传递回调的参数.
现在我得到的错误是:'callback()正好接受2个参数(给定1个)'
from kivy.config import Config
Config.set('graphics', 'width', '600')
Config.set('graphics', 'height', '300')
Config.set('graphics', 'resizable', 0)
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.uix.switch import Switch
Builder.load_file('hueLayout.kv')
class hueLayout(BoxLayout):
pwr1_switch = ObjectProperty()
def callback(instance, value):
print 'instance: ', instance
print 'value: ', value
#pwr1_switch.bind(pwr1_switch, active=callback)
class HueController(App):
def build(self):
#self._app_window_size = 5, 20
return hueLayout()
if __name__ == '__main__':
Config.write()
HueController().run()
Run Code Online (Sandbox Code Playgroud)
<hueLayout>:
#size_hint: .5, .5
#pos_hint: {'center_x': …Run Code Online (Sandbox Code Playgroud) 我基本上试图从播放列表中提取歌曲名称,然后我想为播放列表中的每首歌创建一个类,其中包括该歌曲的所有相关数据(歌曲标题,艺术家,每首歌曲的位置等)
我有一个列表,其中列表中的每个项目都是歌曲名称.我正在尝试创建一个循环,创建一个以列表中的每个项目命名的新类.
这是我到目前为止:
class MyClass():
var = "hi"
songNames = ['song1', 'song2', 'song3']
for name in songNames:
name = MyClass()
Run Code Online (Sandbox Code Playgroud)
这是行不通的,我认为这是因为Python遇到了麻烦/无法为这样的类分配名称.我是Python的初学者,经过广泛的搜索,我无法想出一个解决方案.这样做的正确方法是什么?
所以我一直在研究代码并取得了一些进展:
class SongData(object):
def __init__(self, title="", artist="", directory=""):
self.title, self.artist, self.directory = title, artist, directory
def __str__(self):
desc_str = "Title: %s \nArtist: %s \nDirectory: %s \n" %(self.title,
self.artist, self.directory)
print desc_str
songNames = ['song1', 'song2', 'song3']
artistNames = ['artist1', 'artist2', 'artist3']
dirNames = ['dir1', 'dir2', 'dir3']
songs = {name: SongData(title=name) for name in songNames}
artists = {band: SongData(artist=band) for …Run Code Online (Sandbox Code Playgroud)