omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. Ahab3030

    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.


    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 5
    • Best 1
    • Controversial 0
    • Groups 0

    Ahab3030

    @Ahab3030

    1
    Reputation
    375
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Ahab3030 Unfollow Follow

    Best posts made by Ahab3030

    • RE: Button won’t show up, and can’t get result to show up on result Label. Please help

      That worked! Thanks everyone I can’t believe how fast you all provided help.

      posted in Pythonista
      Ahab3030
      Ahab3030

    Latest posts made by Ahab3030

    • RE: Can not get segmented control to pass variable

      @cvp that worked great! Thanks a lot, post at night answer by morning I love this forum!

      posted in Pythonista
      Ahab3030
      Ahab3030
    • Can not get segmented control to pass variable

      I am trying to make a voltage drop calculator but it keep getting an error message that a string can’t be converted to a float, and when I look in the vars the cm, and con values show up as ‘ ‘. So I am doing something wrong. Please help!

      # importing mods for equation and gui
      
      import ui
      import math
      
      # setting up view that the sub views can be inside and nameing the view
      
      view = ui.View()
      view.name = 'Voltage Drop'
      view.background_color = '#ffffff'
      
      # Variables E: voltage, L: length, I: amprage, con: conducter material, cm: circular mills of the chosen conducter.
      
      E = str()
      L = str()
      I = str()
      con = str()
      cm = str()
      
      # attempt at place holder for conductor resistence value
      
      ConLbl = ui.Label()
      ConLbl.text = con
      ConLbl.name = 'Conducter Value'
      ConLbl.x = 155
      ConLbl.y = 380
      ConLbl.width = 60
      ConLbl.height = 20
      ConLbl.border_width = 1
      view.add_subview(ConLbl)
      
      
      # variables for copper and aluminium
      
      def segment_action(sender):
      	con = ConLbl.text
      	if sender.selected_index == 0:
      		sender.superview['Conducter Value'].text = '12.9'
      	elif sender.selected_index == 1:
      		sender.superview['Conducter Value'].text = '21.2'
      	
      # label for conductor
      
      cLbl = ui.Label()
      cLbl.text = 'Conductor'
      cLbl.x = 140
      cLbl.y = 5
      view.add_subview(cLbl)
      
      # segmented control for conductor material
      
      cOa = ui.SegmentedControl(con)
      cOa.segments = ('Copper', 'Aluminium')
      cOa.action = segment_action
      cOa.x = 80
      cOa.y = 70
      cOa.width = 200
      view.add_subview(cOa)
      
      # label for wire gauge
      
      awgLbl = ui.Label()
      awgLbl.text = 'AWG'
      awgLbl.x = 165
      awgLbl.y = 90
      view.add_subview(awgLbl)
      
      # attempt at place holder for cm value
      
      cmLbl = ui.Label()
      cmLbl.text = cm
      cmLbl.name = 'CM Value'
      cmLbl.x = 155
      cmLbl.y = 410
      cmLbl.width = 60
      cmLbl.height = 20
      cmLbl.border_width = 1
      view.add_subview(cmLbl)
      
      # segmented control action and variables for wire gauge in AWG
      
      def segment_action2(sender):
      	if sender.selected_index == 0:
      		sender.superview['CM Value'].text = '4107'
      	elif sender.selected_index == 1:
      		sender.superview['CM Value'].text = '6530'
      	elif sender.selected_index == 2:
      		sender.superview['CM Value'].text = '10383'
      	elif sender.selected_index == 3:
      		sender.superview['CM Value'].text = '16509'
      	elif sender.selected_index == 4:
      		sender.superview['CM Value'].text = '26251'
      	elif sender.selected_index == 5:
      		sender.superview['CM Value'].text = '41740'
      	elif sender.selected_index == 6:
      		sender.superview['CM Value'].text = '66369'
      	elif sender.selected_index == 7:
      		sender.superview['CM Value'].text = '105518'
      	elif sender.selected_index == 8:
      		sender.superview['CM Value'].text = '133056'
      	elif sender.selected_index == 9:
      		sender.superview['CM Value'].text = '167780'
      	elif sender.selected_index == 10:
      		sender.superview['CM Value'].text = '211566'
      
      # segmented control for awg selection
      
      awg = ui.SegmentedControl(cm)
      awg.segments = ('14', '12', '10', '8', '6', '4', '2', '1/0', '2/0', '3/0', '4/0')
      awg.action = segment_action2
      awg.x = 15
      awg.y = 150
      awg.width = 350
      view.add_subview(awg)
      
      # label for voltage
      
      vLbl = ui.Label()
      vLbl.text = 'Voltage'
      vLbl.x = 160
      vLbl.y = 140
      view.add_subview(vLbl)
      
      #text feild for voltage input
      
      volts= ui.TextField(E)
      volts.x = 155
      volts.y = 200
      volts.width = 60
      volts.border_width = 1
      volts.height = 20
      view.add_subview(volts)
      
      # label for length of wire run
      
      LenLbl = ui.Label()
      LenLbl.text = 'Length'
      LenLbl.x = 160
      LenLbl.y = 200
      view.add_subview(LenLbl)
      
      # text feild input for length (L)
      
      length = ui.TextField(L)
      length.x = 155
      length.y = 260
      length.width = 60
      length.border_width = 1
      length.height = 20
      view.add_subview(length)
      
      # label for amprage
      
      ampsLbl = ui.Label()
      ampsLbl.x = 160
      ampsLbl.y = 265
      ampsLbl.text = 'Amps'
      view.add_subview(ampsLbl)
      
      #text feild input for amprage(I)
      
      amps = ui.TextField(I)
      amps.x = 155
      amps.y = 330
      amps.width = 60
      amps.height = 20
      amps.border_width = 1
      view.add_subview(amps)
      
      # label for result
      
      resLbl = ui.Label()
      resLbl.text = 'Result'
      resLbl.x = 150
      resLbl.y = 420
      view.add_subview(resLbl)
      
      
      
      # label that shows result voltage drop calc
      
      Result = ui.Label()
      Result.text = str()
      Result.x = 100
      Result.y = 500
      Result.width = 200
      Result.height = 20
      Result.border_width = 1
      view.add_subview(Result)
      
      # function for voltage drop calc performed after inputs and button pushed
      
      def button_tapped(sender):
      	I = float(amps.text)
      	L = float(length.text)
      	E = float(volts.text)
      	Result.text = (2*float(con)*float(L)*float(I))/float(cm)
      
      # button to run calc after inputs are entered
      
      button = ui.Button(frame=[150, 550, 100, 40], title='  Calculate  ')
      button.background_color=('white')
      button.action = button_tapped
      button.tint_color = ('black')
      button.border_width = 2
      view.add_subview(button)
      
      # establishing parent view for child views to present in
      
      view.present('fullscreen') ```
      posted in Pythonista
      Ahab3030
      Ahab3030
    • RE: Button won’t show up, and can’t get result to show up on result Label. Please help

      That worked! Thanks everyone I can’t believe how fast you all provided help.

      posted in Pythonista
      Ahab3030
      Ahab3030
    • RE: Button won’t show up, and can’t get result to show up on result Label. Please help

      Thanks y’all I will give that a try!

      posted in Pythonista
      Ahab3030
      Ahab3030
    • Button won’t show up, and can’t get result to show up on result Label. Please help

      I am trying to make a simple GUI in UI that will give me the hypotenuse from 2 numbers A and B. the button was displayed, but went away(not sure why). I can write numbers in the upper 2 text field’s and I’d like the button to perform a hypotenuse calc on the numbers and display it in 3rd field, which for some reason I believe needs to be a label and not TextField. Any help is appreciated. Thanks!

      ————————————————————————————————————————————————————————

      import ui
      import math
      import string
      
      
      view = ui.View()
      view.name = 'hypotenuse'
      view.background_color = 'white'
      
      # variables for lengths A and B
      
      A = float()
      B = float()
      
      # label for length
      
      LenLbl = ui.Label()
      LenLbl.text = 'Length'
      LenLbl.x = 370
      LenLbl.y = 80
      
      # text feild input for length (A)
      
      Length = ui.TextField(A)
      Length.x = 300
      Length.y = 150
      Length.width = 200
      Length.border_width = 1
      
      # label for width
      
      widLbl = ui.Label()
      widLbl.text = 'Width'
      widLbl.x = 370
      widLbl.y = 280
      
      # text feild input for width (B)
      
      Width = ui.TextField(B)
      Width.x = 300
      Width.y = 350
      Width.width = 200
      Width.border_width = 1
      
      # label for result
      
      resLbl = ui.Label()
      resLbl.text = 'Result'
      resLbl.x = 370
      resLbl.y = 480
      
      # label that should show result of hypotenuse of A and B when button is pushed
      
      Result = ui.Label()
      Result.text = str()
      Result.x = 300
      Result.y = 550
      Result.width = 200
      Result.border_width = 1
      
      # math for hypot calc
      
      C = math.hypot(A, B)
      
      # attempt at getting button to perform calc and put result in result Label
      
      def button_tapped(C):
      	Result.text = float(eval(C))
      
      button = ui.Button()
      button.text = ' Calculate '
      button.x = 300
      button.y = 650
      button.action = button_tapped
      button.border_width = 1
      
      # putting items on screen in GUI(only button wont show up)
      
      view.add_subview(Width)
      view.add_subview(widLbl)
      view.add_subview(Length)
      view.add_subview(LenLbl)
      view.add_subview(button)
      view.add_subview(resLbl)
      view.add_subview(Result)
      view.present('fullscreen')
      
      posted in Pythonista
      Ahab3030
      Ahab3030