omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    I need help(again)

    Pythonista
    4
    7
    2398
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NewbieCoder
      NewbieCoder last edited by ccc

      I cant exactly pinpoint what im doing wrong here but im in trouble again)))))

      The a = sender.title line is being completely ignored and nothing shows up in the console

      v = ui.View()
      v.frame = (0,0,400,400)
      v.name = 'test'
      
      b = ui.Button()
      b.title = 'use'
      b.action = 'tap'
      b.background_color = 'white'
      b.border_color = 'blue'
      b.border_width = 1
      b.corner_radius = 5
      b.frame = (10,10,100,32)
      v.add_subview(b)
      
      ba = ui.Button()
      ba.title = 'buy'
      ba.action = 'tap'
      ba.background_color = 'white'
      ba.border_color = 'blue'
      ba.border_width = 1
      ba.corner_radius = 5
      ba.frame = (110,10,100,32)
      v.add_subview(ba)
      
      a = ''
      
      v.present(“sheet”)
      
      while 0 == 0:
      	
      	
      	def tap(sender):
      		'@type sender: ui.Button'
      		a = sender.title
      	print(a)
      
      mikael 1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by ccc

        Lose the quotes around tap because you want the function, not a string.

        Define tap() at the top of you file (before you use it).

        Also, you want to surround your code with three backticks.

        1 Reply Last reply Reply Quote 0
        • mikael
          mikael @NewbieCoder last edited by

          @NewbieCoder, did you already get past this is issue? Hard to tell with multiple posts - maybe keep working on these in the same thread to make the chronology easier to follow? Also, please put all the code you share between three backticks to make it format properly and to make it easier for people helping you.

          Regarding this code, hard to tell without the formatting, but at least the while 0 == 0 loop should be unnecessary.

          NewbieCoder 1 Reply Last reply Reply Quote 0
          • brumm
            brumm last edited by brumm

            import ui   #import needed library
            
            def tap(sender):   #define function before it is called
                print(sender.title)
            
            v = ui.View()
            v.frame = (0,0,400,400)
            v.name = 'test'
            
            b = ui.Button()
            b.title = 'use'
            b.action = tap
            b.background_color = 'white'
            b.border_color = 'blue'
            b.border_width = 1
            b.corner_radius = 5
            b.frame = (10,10,100,32)
            v.add_subview(b)
            
            ba = ui.Button()
            ba.title = 'buy'
            ba.action = tap
            ba.background_color = 'white'
            ba.border_color = 'blue'
            ba.border_width = 1
            ba.corner_radius = 5
            ba.frame = (110,10,100,32)
            v.add_subview(ba)
            
            v.present('sheet')
            

            ui help

            ui Tutorial

            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by ccc

              I highly recommend the UI Tutorial link that @brumm has provided above because it does a great job of building from simple to complex.

              1 Reply Last reply Reply Quote 0
              • NewbieCoder
                NewbieCoder @mikael last edited by

                @mikael the while loop is because i am making an idol clicker type thing and want inputs every time the button is pressed (i started out typing what the buttons would say on them to get the general idea)

                1 Reply Last reply Reply Quote 0
                • ccc
                  ccc last edited by

                  The while True: loop is not needed because view.present() will keep your window active and responding to button clicks, etc. until the user clicks the X in the upper right, does a multi-finger swipe down, etc.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors