Pythonic gui格式? [英] Pythonic gui format?
问题描述
Buenos dias,amigos!
我必须编写_simple_ gui库,用于嵌入游戏。我的第一次尝试是
使用XML:用这样的方式描述ui并不是很可爱:
< window>
< title> Hello World!< / title>
< image text =" nice picture here" pos = ... src = ... />
< text opts = ...>
(此处有些文字)
< / text>
< list>
< item>第一个元素< / item>
< item> second一个...< / item>
< / list>
< button action = ... text =" Click Me!" />
< / window>
(或类似的东西)
但在阅读后 Python不是Java
http:/ /dirtsimple.org/2004/12/python-is-not-java.html (顺便说一句,我不是一个Java程序员)我意识到它实际上并不可爱所有:)(am
我错在这里?)
我目前正在寻找XML的pythonic替代品。一种可能的方法是为每个(类型的?)窗口创建一个类,比如
class SomeDlg(Window):
def __init __(self,dict?):
self.setdict(dict)
self.add_text($ friend愿意和你说话。$ question ;)
self.add_button(action = self.onclick,
text ="是的,我想要$ action!")
...
def onclick(个体经营):
#此处处理数据,发送消息等
有点丑陋吗?另一种变体是
dlg = Window(dict,[opts])
dlg.text(" text here",[opts])
dlg.image(src,pos,text [etc])
.....
或者可能
dlg =窗口(...)
dlg.text =文字(...)
dlg.button =按钮(... )
....
dlg.display(表面)
这些款式当然可以合并......但恕我直言看起来不是很很好
:(也许我不会依赖内省?任何建议,评论,
的想法和链接都是受欢迎的。
谢谢。
问题") b $ b self.add_button(action = self.onclick,
text ="是的,我想
action!")< br $> b $ b ...
def onclick(个体经营):
#此处处理数据,发送一些消息等
不是吗有点?另一种变体是
dlg = Window(dict,[opts])
dlg.text(" text here",[opts])
dlg.image(src,pos,text [etc])
.....
或者可能
dlg =窗口(...)
dlg.text =文字(...)
dlg.button =按钮(... )
....
dlg.display(表面)
这些款式当然可以合并......但恕我直言看起来不是很很好
:(也许我不会依赖内省?任何建议,评论,
的想法和链接都是受欢迎的。
谢谢。
Buenos dias, amigos!
I have to write _simple_ gui library, for embedding into game. My
first attempt was to use XML: isn''t it cute to describe ui in such a
way:
<window>
<title>Hello World!</title>
<image text="nice picture here" pos=... src=... />
<text opts=...>
(some text here)
</text>
<list>
<item>first element</item>
<item>second one...</item>
</list>
<button action=... text="Click Me!" />
</window>
(or something similar)
But after reading "Python Is Not Java"
http://dirtsimple.org/2004/12/python-is-not-java.html (BTW I''m not a
Java programmer) I realised that it is actually not cute at all :) (am
I wrong here?)
I am currently seeking for pythonic alternative for XML. One possible
way is to create a class for every (type of?) window, like
class SomeDlg(Window):
def __init__(self, dict?):
self.setdict(dict)
self.add_text("$friend would like to speak to you. $question")
self.add_button(action=self.onclick,
text="Yeah, I''d like to $action !")
...
def onclick(self):
# process data here, send some messages etc.
Isn''t it ugly a bit? Another variant is
dlg = Window(dict, [opts])
dlg.text("text here", [opts])
dlg.image(src, pos, text [etc])
.....
or possibly
dlg = Window(...)
dlg.text = Text(...)
dlg.button = Button(...)
....
dlg.display(surface)
These styles of course can be combined... But IMHO looks not very nice
:( Maybe I shall not rely on introspection? Any suggestions, comments,
thoughts and links are welcome.
Thanks.
friend would like to speak to you.
question")
self.add_button(action=self.onclick,
text="Yeah, I''d like to
action !")
...
def onclick(self):
# process data here, send some messages etc.
Isn''t it ugly a bit? Another variant is
dlg = Window(dict, [opts])
dlg.text("text here", [opts])
dlg.image(src, pos, text [etc])
.....
or possibly
dlg = Window(...)
dlg.text = Text(...)
dlg.button = Button(...)
....
dlg.display(surface)
These styles of course can be combined... But IMHO looks not very nice
:( Maybe I shall not rely on introspection? Any suggestions, comments,
thoughts and links are welcome.
Thanks.
这篇关于Pythonic gui格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!