How would you design a very “Pythonic” UI framework?

后端 未结 15 1808
日久生厌
日久生厌 2021-02-02 01:29

I have been playing with the Ruby library \"shoes\". Basically you can write a GUI application in the following way:

Shoes.app do
  t = para \"Not clicked!\"
  b         


        
15条回答
  •  粉色の甜心
    2021-02-02 01:37

    With some Metaclass magic to keep the ordering I have the following working. I'm not sure how pythonic it is but it is good fun for creating simple things.

    class w(Wndw):
      title='Hello World'
      class txt(Txt):  # either a new class
        text='Insert name here'
      lbl=Lbl(text='Hello') # or an instance
      class greet(Bbt):
        text='Greet'
        def click(self): #on_click method
          self.frame.lbl.text='Hello %s.'%self.frame.txt.text
    
    app=w()
    

提交回复
热议问题