def __init__(self): self.Text = "ComboBox" self.Size = Size(240, 240) cb = ComboBox() cb.Parent = self cb.Location = Point(50, 30) cb.Items.AddRange( ("Ubuntu", "Mandriva", "Red Hat", "Fedora", "Gentoo")) cb.SelectionChangeCommitted += self.OnChanged self.label = Label() self.label.Location = Point(50, 140) self.label.Parent = self self.label.Text = "..." self.CenterToScreen()
def __init__(self): self.Text = "ComboBox" self.Size = Size(240, 240) cb = ComboBox() cb.Parent = self cb.Location = Point(50, 30) cb.Items.AddRange(("Ubuntu", "Mandriva", "Red Hat", "Fedora", "Gentoo")) cb.SelectionChangeCommitted += self.OnChanged self.label = Label() self.label.Location = Point(50, 140) self.label.Parent = self self.label.Text = "..." self.CenterToScreen()
if isinstance(IN[1], list): inputtypes = IN[1] else: inputtypes = [IN[1]] for i, j in zip(inputnames, inputtypes): label = Label() label.Location = Point(xlabel, y + 4 * resfactY) label.Height = 20 * resfactY label.Width = 80 * resfactX label.Text = str(i) form.Controls.Add(label) if isinstance(j, list): cb = ComboBox() cb.Location = Point(xinput, y) cb.Width = 150 * resfactX globals()['dict%d' % (cbindex)] = {} try: for k in j: globals()['dict%d' % (cbindex)][k.Name] = k cb.Items.Add(k.Name) except: for k in j: try: globals()['dict%d' % (cbindex)][str(k)] = k except: globals()['dict%d' % (cbindex)][k.encode('utf-8').decode('utf-8')] = k cb.Items.Add(k) form.Controls.Add(cb)
def __init__(self): #the __init__ method inside a class is its constructor self.Text = "AU London" #text that appears in the GUI titlebar self.Icon = Icon.FromHandle( icon.GetHicon() ) #takes a bitmap image and converts to a file that can be used as a Icon for the titlebar self.BackColor = Color.FromArgb(255, 255, 255) self.WindowState = FormWindowState.Normal # set maximised minimised or normal size GUI self.CenterToScreen() # centres GUI to the middle of your screen self.BringToFront() #brings the GUI to the front of all opens windows. self.Topmost = True # true to display the GUI infront of any other active forms screenSize = Screen.GetWorkingArea( self ) #get the size of the computers main screen, as the form will scale differently to different sized screens self.Width = screenSize.Width / 4 #set the size of the form based on the size of the users screen. this helps to ensure consistant look across different res screens. self.Height = screenSize.Height / 4 uiWidth = self.DisplayRectangle.Width #get the size of the form to use to scale form elements uiHeight = self.DisplayRectangle.Height #self.FormBorderStyle = FormBorderStyle.FixedDialog # fixed dialog stops the user from adjusting the form size. Recomended disabling this when testing to see if elements are in the wrong place. self.userOutput = userOutputDefaultStr #create a container to store the output from the form self.runNextOutput = False #set these default values #############-------------\-------------############# spacing = 10 #spacing size for GUI elements to form a consistent border # creates the text box for a info message userMessage = Label() #label displays texts font = Font("Helvetica ", 10) userMessage.Text = message userMessage.Font = font userMessage.Location = Point( spacing, spacing ) #all location require a point object from system.Drawing to set the location. userMessage.Size = Size( uiWidth - (spacing * 2), (uiHeight / 4) ) #size the control with the width of the GUI to ensure it scales with different screen self.Controls.Add(userMessage) #this adds control element to the GUI #############-------------\-------------############# #logo file logo = PictureBox() logo.Image = logoFile ratio = float(logo.Height) / float( logo.Width ) #needs to be a float as int will round to the nearest whole number logo.Size = Size( uiWidth / 4, (uiHeight / 4) * ratio ) #scale the image by the ratio between the images height & width logo.Location = Point(spacing, (uiHeight - logo.Height) - spacing) logo.SizeMode = PictureBoxSizeMode.Zoom # zooms the image to fit the extent logo.Anchor = ( AnchorStyles.Bottom | AnchorStyles.Left ) #anchor styles lock elements to a given corner of the GUI if you allow users change size self.Controls.Add(logo) #logo.BorderStyle = BorderStyle.Fixed3D #gives a border to the panel to test its location #############-------------\-------------############# #combox drop down cBox = ComboBox() #dropdown control form cBox.Location = Point(spacing, uiHeight / 3) cBox.Width = uiWidth - (spacing * 2) cBox.Items.AddRange( listInput ) # Adds an array of items to the list of items for a ComboBox. cBox.DropDownStyle = ComboBoxStyle.DropDownList #setting to dropdown list prevents users from being able to add aditional text values cBox.SelectedIndexChanged += self.dropDownOutput #.Click+= registers the press of the button to register the event handler and determine what action takes place when button clicked self.Controls.Add(cBox) #############-------------\-------------############# #Create ok button btnOk = Button() #create a button control btnOk.Text = "Next" btnOk.Location = Point(uiWidth - ((btnOk.Width * 2) + spacing), uiHeight - (btnOk.Height + spacing)) btnOk.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right) btnOk.Click += self.okButtonPressed #Register the event on the button bress to trigger the def okButtonPressed self.Controls.Add(btnOk) #Create Cancel Button btnCancel = Button() #btnCancel.Parent = self btnCancel.Text = "Cancel" btnCancel.Location = Point(uiWidth - (btnOk.Width + spacing), uiHeight - (btnOk.Height + spacing)) btnCancel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right) btnCancel.Click += self.CnlButtonPressed self.Controls.Add(btnCancel)