def makeSubmitMenuGUI(score, window): '''Creates the GUI for the submission screen''' message = "Score To Submit: " + str(score) messText = gfx.Text(gfx.Point(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 6 * 2), message) nameText = gfx.Text( gfx.Point(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 6 * 3 - 50), "Enter your name:") inputBox = gfx.Entry(gfx.Point(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 6 * 3), 25) submitSprites, \ submitButton = button.create(WINDOW_HEIGHT// 6 * 4, "Submit", window) messText.setFill("red") messText.setSize(36) error = "Text must be between 3 and 25 chars, and contain no '`' character." errorMessage = gfx.Text( gfx.Point(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 6 * 3.50), error) errorMessage.setStyle("bold") errorMessage.setFill("red") return [messText, nameText ] + submitSprites, errorMessage, inputBox, submitButton
def __init__(self): # initialize window self.win = graphics.GraphWin("Aurora B Consensus Seq Finder", 800, 400) # transform coordinates self.win.setCoords(0, 0, 400, 400) # draw button self.run_prog_button = Button(320, 20, self.win, 'green') self.run_prog_button.text('Search') # draw text input boxes self.protein_list_input = graphics.Entry(graphics.Point(200, 200), 70) self.protein_list_input.draw(self.win) # write instructions text_pt = graphics.Point(200, 300) text_message = """Welcome to the Aurora B Kinase Consensus Search Program! Please input a URL linking to the fungal alignment for a protein of interest on the SGD in the textbox below, and then click "Search". It may take a moment for the program to run. The window will close when the created file is saved. Example test URL: https://www.yeastgenome.org/cache/fungi/YGR113W.html """ text_obj = graphics.Text(text_pt, text_message) text_obj.draw(self.win) # initialize useful variables for later self.protein_list = None
def ten_strings(): input_box = g.Entry(g.Point(50, 50), 10) input_box.draw(win) for i in range(10): m = win.getMouse() text = g.Text(g.Point(m.getX(), m.getY()), input_box.getText()) text.draw(win)
def chooseDif(): difwin = graphics.GraphWin("Choose Difficulty", 200, 200) label = graphics.Text( Point(difwin.getWidth() / 2, difwin.getHeight() / 2 - 50), 'Enter Difficulty level') label.draw(difwin) difwin.focus() entry = graphics.Entry( Point(difwin.getWidth() / 2, difwin.getHeight() / 2 + 50), 5) entry.setTextColor('green') entry.setFill('white') entry.setSize(12) entry.setFace("courier") entry.setText("2") entry.draw(difwin) message = graphics.Text( Point(difwin.getWidth() / 2, difwin.getHeight() / 2 + 80), 'Click anywhere within the window to quit.') message.setTextColor('red') message.setStyle('italic') message.setSize(8) message.draw(difwin) difwin.getMouse() optu = int(entry.getText()) Minmax.setDifficulty(optu) difwin.close()
def attack(): global playerHp global mobHp while playerHp > 1 and mobHp > 1: inp = "" textPrint("Choose a number between 0 and 9") inputBox = graphics.Entry(textPoint, 1) while inp != "0" and inp != "1" and inp != "2" and inp != "3" and inp != "4" and inp != "5" and inp != "6" and inp != "7" and inp != "8" and inp != "9": inputBox.draw(win1) win1.getMouse() inp = inputBox.getText() inputBox.undraw() number = random.randint(-10, 20) if number > int(inp): textPrint("Alas! You were dealt a blow.") playerHp -= mob["Power"] else: textPrint("A direct hit!") mobHp -= 3 fillText = Rectangle(Point(455, 165), Point(465, 175)) fillText.setFill("black") fillText.draw(win1) textPut(460, 170, mobHp) fillText = Rectangle(Point(600, 365), Point(620, 375)) fillText.setFill("black") fillText.draw(win1) textPut(610, 370, playerHp)
def input_GUI(): """ Creats the name input window """ loop_ = True win = graph.GraphWin("input", 500, 300) win.setCoords(0, 0, 10, 10) in_banner_msg = graph.Text( graph.Point(5, 7), "Type your name followed by clicking the window").draw(win) in_banner_msg.setSize(15) while loop_ is True: name_in = graph.Entry(graph.Point(5, 5), 7).draw(win) win.getMouse() if name_in.getText(): loop_ = False else: empty_msg = graph.Text(graph.Point(5, 4), "Type youre name").draw(win) empty_msg.setSize(20) loop_ = True win.close() return name_in.getText()
def input(): inp = "" inputBox = graphics.Entry(textPoint, 1) while inp != "N" and inp != "S" and inp != "D" and inp != "S" and inp != "I" and inp != "B" and inp != "?": inputBox.draw(win1) win1.getMouse() inp = inputBox.getText() inputBox.undraw() return inp
def encounterInput(): inp = "" inputBox = graphics.Entry(textPoint, 1) while inp != "A" and inp != "F": inputBox.draw(win1) win1.getMouse() inp = inputBox.getText() inputBox.undraw() return inp
def chooseDif(): difwin = graphics.GraphWin("Choose Difficulty") difwin.focus() entry = graphics.Entry(Point(100, 100), 20) entry.setText("2") entry.draw(difwin) difwin.getMouse() DIFFICULTY = int(entry.getText()) difwin.close()
def _setupNumberEntry(self): characterSize = 3 entryPosition = gx.Point(self.position[0] + 2 * self.size[0] / 10, self.position[1] + self.size[1] / 2) self.numberEntry = gx.Entry(entryPosition, characterSize) self.numberEntry.setFace('times roman') self.numberEntry.setText(str(self.number)) self.numberEntry.setStyle('bold') self.numberEntry.setSize(14)
def chooseOption(): OptionWindow = graphics.GraphWin("Choose an option", 300, 250) # OptionWindow.setBackground('#E59866') label = graphics.Text( Point(OptionWindow.getWidth() / 2, OptionWindow.getHeight() / 2 - 100), 'Choose one from following options?') label.draw(OptionWindow) label1 = graphics.Text( Point(OptionWindow.getWidth() / 2, OptionWindow.getHeight() / 2 - 60), '1. Human v/s Minimax Bot') label1.draw(OptionWindow) label2 = graphics.Text( Point(OptionWindow.getWidth() / 2, OptionWindow.getHeight() / 2 - 40), '2. Human v/s Random Bot') label2.draw(OptionWindow) label3 = graphics.Text( Point(OptionWindow.getWidth() / 2, OptionWindow.getHeight() / 2 - 20), '3. Minimax Bot v/s Minimax Bot') label3.draw(OptionWindow) label4 = graphics.Text( Point(OptionWindow.getWidth() / 2, OptionWindow.getHeight() / 2), '4. Random Bot v/s Random Bot') label4.draw(OptionWindow) label5 = graphics.Text( Point(OptionWindow.getWidth() / 2, OptionWindow.getHeight() / 2 + 20), '5. Random Bot v/s Minimax Bot') label5.draw(OptionWindow) OptionWindow.focus() entry = graphics.Entry( Point(OptionWindow.getWidth() / 2, OptionWindow.getHeight() / 2 + 50), 5) entry.setTextColor('green') entry.setFill('white') entry.setSize(12) entry.setFace("courier") entry.setText("1") entry.draw(OptionWindow) message = graphics.Text( Point(OptionWindow.getWidth() / 2, OptionWindow.getHeight() / 2 + 80), 'Click anywhere within the window to quit.') message.setTextColor('red') message.setStyle('italic') message.setSize(8) message.draw(OptionWindow) OptionWindow.getMouse() optu = int(entry.getText()) OptionWindow.close() globalVariables.option = optu
def ten_coloured_rectangles(): input_box = g.Entry(g.Point(50, 50), 10) input_box.draw(win) for i in range(10): m = win.getMouse() point_a = g.Point(m.getX(), m.getY()) m = win.getMouse() point_b = g.Point(m.getX(), m.getY()) rectangle = g.Rectangle(point_a, point_b) rectangle.setFill(input_box.getText()) rectangle.draw(win)
def chooseDif():] difwin = graphics.GraphWin("Choose Difficulty") difwin.focus() entry = graphics.Entry(Point(100, 100), 20) entry.setText("2") entry.draw(difwin) label = Text(Point(100, 130), 'Please choose difficulty between 1 - 10') label.setSize(9) label.draw(difwin) difwin.getMouse() ai.DIFFICULTY = int(entry.getText()) difwin.close()
def __init__(self, win, p1, p2, background='white'): super().__init__(win, p1, p2, background) self.input = graphics.Entry( Point(self.getCenter().getX(), INPUT_PANEL_BOTTOM - TEXT_MARGIN_Y), INPUT_WIDTH) self.makeText('This is the prompt') self.text.setSize(PROMPT_SIZE) self.text.move( 0, self.getP1().getY() - self.getCenter().getY() + TEXT_MARGIN_Y) self.input.setSize(TEXT_SIZE) self.input.setFill(INPUT_PANEL_BACKGROUND) self.input.draw(win)
def collect_input(self): Angle = gr.Text(gr.Point(1230, 300), 'Angle = ') Angle.setTextColor('white') Angle.setSize(20) Angle.draw(self.win) input_box_angle = gr.Entry(gr.Point(1300, 300), 5).draw(self.win) velocity = gr.Text(gr.Point(1220, 200), 'Velocity = ') velocity.setTextColor('white') velocity.setSize(20) velocity.draw(self.win) input_box_velocity = gr.Entry(gr.Point(1300, 200), 5).draw(self.win) input_box_angle.setText('1.3') input_box_velocity.setText('200') self.draw_start_button(1300, 400, 30) if self.check_start_button() == True: initial_angle = float(input_box_angle.getText()) initial_v_x = float( input_box_velocity.getText()) * np.cos(initial_angle) initial_v_y = float( input_box_velocity.getText()) * np.sin(initial_angle) self.initial_velocity = Velocity(initial_v_x, initial_v_y, self.initial_time, self.rules)
def main(): def drawRectangle(i, salesNum): print('num', salesNum) p1x = i * 100 p1y = 85 p2x = p1x + 100 p2y = 140 rectangle = g.Rectangle(g.Point(p1x, p1y), g.Point(p2x, p2y)) rectangle.draw(win) g.Text( g.Point( i * 100 + 50, 112 ), salesNum ).draw( win ) def addToTotal(total, salesNum): return total + salesNum def calcAvg(total): return total / 3 def printTotalAndAvg(total, avg): g.Text(g.Point(60, 180), 'Total: ' + str(total)).draw(win) g.Text(g.Point(280, 180), 'Average: ' + str(avg)).draw(win) # initialize window win = g.GraphWin('Donuts Sold', 640, 200) # draw entry box for sales numbers g.Text( g.Point( 60, 40 ), 'Enter Sales: ' ).draw( win ) entry = g.Entry(g.Point(140, 40), 10) entry.setFill('white') entry.draw(win) # draw axis line g.Line(g.Point(100, 75), g.Point(100, 150)).draw(win) # initialize running total total = 0 for clickCount in range(1, 4): clickPoint = win.getMouse() userEntry = int(entry.getText()) drawRectangle(clickCount, userEntry) total = addToTotal(total, userEntry) print('total', total) avg = calcAvg(total) print('average', avg) printTotalAndAvg(total, avg)
def inventory(): global northDir global ownedItems northDir = 2 roomEnter() inp = "" inputBox = graphics.Entry(textPoint, 1) textPut(400, 100, textCentre("Inventory")) textPut(100, 133, "Item") textPut(300, 133, "Power") textPut(500, 133, "Defense") textPut(700, 133, "Regen") #textPut(100, 200, item["Name"]) inputBox.draw(win1) win1.getMouse() inp = inputBox.getText() inputBox.undraw()
def __init__(self): # Create Window self.win = g.GraphWin("Chord Practice", 500, 500) # Form to enter Beats per Minute self.form_bpm = g.Entry(g.Point(370, 50), 5) self.form_bpm.setText("12") # Init as 12 self.form_bpm.draw(self.win) self.bpm = 12 # Label for bpm self.label_bpm = g.Text(g.Point(180, 50), "Beats per minute") self.label_bpm.draw(self.win) # Root Note Display self.root = g.Text(g.Point(240, 250), rootdict[0]) self.root.draw(self.win) self.root.setSize(36) # Intonation Display self.intonation = g.Text(g.Point(270, 240), "b") self.intonation.setSize(30) self.intonation.draw(self.win) # Mode Display self.mode = g.Text(g.Point(270, 260), "-") self.mode.setSize(36) self.mode.draw(self.win) # Seven alterations self.seven = g.Text(g.Point(308, 233), "7") self.seven.setSize(18) # Alteration Symbols to draw self.maj = g.Polygon(g.Point(285, 240), g.Point(300, 240), g.Point(292.5, 225)) self.diminished = g.Circle(g.Point(292.5, 232.5), 7) self.halfdim = g.Line(g.Point(285, 240), g.Point(301, 224)) self.sevendrawn = False self.dimdrawn = False self.halfdimdrawn = False self.majdrawn = False
def get_new_score_name(): """gets the nane of the player to add to the highscore board""" name_window = g.GraphWin("Name", 200, 200) get_name = g.Text(g.Point(100, 80), "Name") click_conf = g.Text(g.Point(100, 120), "Click to continue") name_enter = g.Entry(g.Point(100, 100), 10) get_name.draw(name_window) click_conf.draw(name_window) name_enter.draw(name_window) name_window.getMouse() name = str(name_enter.getText()) name_window.close() return name
def __init__(self, x, y, width, win): """ x, y, width, gaphWin """ self.x = x self.y = y self.img = g.Entry(g.Point(self.x, self.y), width) self.img.draw(win)
def main(win): """The main code of the program""" #Create the board & buttons buttons = createBoard(win) # Make a nested list for ring centers centerLst = [] for i in range(9): centerLst.append([]) #centerLst = [[Si Centers], [O], [General Ring], [4 Membered], [5 Membered], [6 Membered], # [7 Membered], [8 Membered], [9 Membered]] # Define Lists to be used later colorLst = ['#1DAA43', '#FF1D0F', '#F8A61E', '#9E4BF6', '#4BB0F6', \ '#43C47F', '#F9DE3E', '#F94C3E', '#F726E8'] #Colors for rings labelLst = ['Si', 'O', 'GR', '4', '5', '6', '7', '8', '9'] #Labels for rings ringLst = [] #List to store ring objects #Check if a button is clicked & place rings until user clicks FINISH loop1 = True while loop1: mousePress = win.getMouse() #Place rings when button is clicked for i in range(9): if buttons[i].clicked(mousePress): placeCenter(win, buttons[i], buttons[12], centerLst[i], \ ringLst, buttons, colorLst[i], labelLst[i]) #REMOVE atoms/rings when button is clicked if buttons[10].clicked(mousePress): #Deactivate all buttons except REMOVE and DONE for i in range(10): buttons[i].deactivate() buttons[11].deactivate() #Select rings to remove while buttons[10].getOutlineColor() == 'yellow': mousePress = win.getMouse() for ring in ringLst: if ring.clicked(mousePress): #Remove center from corresponding list center = ring.getCenter() for j in range(len(labelLst)): if ring.getLabel() == labelLst[j]: print(labelLst[j]) print("alppage") centerLst[j].remove(center) #remove the ring ring.removeRing() ringLst.remove(ring) if checkDone(mousePress, buttons[12]) == True: resetButtons(buttons) #if autofind buttons pressed, run autofind function if buttons[9].clicked(mousePress): autoFind(win, centerLst, ringLst, colorLst, labelLst) #Input dimensions of photo when FINISH is clicked elif buttons[11].clicked(mousePress): #Exist fist while loop loop1 = False #Deactivate all buttons for i in buttons: i.deactivate() #Find pixel -> nm conversion factor #Enter Pixel dimensions instruction3 = graphics.Text(graphics.Point(250, 265), "3.) Enter the size of the image file in pixels. \ \n Note that the entry must include a decimal point.\n(ex. 900.0 x 900.0 pixels)") instruction3.draw(win) #Enter nm dimensions instruction4 = graphics.Text(graphics.Point(250, 360), "4.) Enter the size of the image file in nanometers (nm). \ \n Note that the entry must include a decimal point.\n(ex. 5.0 x 5.0 nm)") instruction4.draw(win) #Set up entry boxes for user nmBoxH = graphics.Entry(graphics.Point(282, 405), 7) nmBoxH.draw(win) text2 = graphics.Text(graphics.Point(237.5, 405), "X") text2.draw(win) txtLabel2 = graphics.Text(graphics.Point(330, 405), "nm") txtLabel2.draw(win) nmBoxW = graphics.Entry(graphics.Point(194, 405), 7) nmBoxW.draw(win) pixBoxH = graphics.Entry(graphics.Point(282, 310), 7) pixBoxH.draw(win) text = graphics.Text(graphics.Point(237.5, 310), "X") text.draw(win) txtLabel = graphics.Text(graphics.Point(340, 310), "pixels") txtLabel.draw(win) pixBoxW = graphics.Entry(graphics.Point(194, 310), 7) pixBoxW.draw(win) enterButton2 = Button(win, graphics.Point(425, 405), 85, 20, '#52E643', 'ENTER') #Program dimensions enter button loop2 = True while loop2: mousePress = win.getMouse() if enterButton2.clicked(mousePress): #enterButton2.deactivate() #Sore values of dimensions nmHeight = nmBoxH.getText() nmWidth = nmBoxW.getText() pixHeight = pixBoxH.getText() pixWidth = pixBoxW.getText() #Check the user input values are decimals if checkDecimal(nmHeight) and checkDecimal(nmWidth) and checkDecimal(pixHeight) \ and checkDecimal(pixWidth): #Calculate average conversion factor convtFact = (((float(nmWidth) / float(pixWidth)) + \ (float(nmHeight) / float(pixHeight))) / 2) #Finish the program after user has input dimensions instruction5 = graphics.Text(graphics.Point(250, 450), "5.) Click on the buttons below to finish the program.") instruction5.draw(win) enterButton2.deactivate() #Exit second while loop loop2 = False else: errorMessage('Please enter dimensions as decimals. \n (ex. 900.0 x 900.0 pixels)') enterButton2.activate() #Create final buttons exportButton = Button(win, graphics.Point(100, 520), 100, 40, '#FFEE33', 'Export to \n xyz File') exportButton.setBoldText() distButton = Button(win, graphics.Point(250, 520), 150, 40, '#33D6FF', 'Show Distribution \n Graph') distButton.setBoldText() quitButton = Button(win, graphics.Point(400, 520), 100, 40, '#FF3369', 'QUIT') quitButton.setBoldText() #List of labels textLst = ['Si', 'O ', 'GR', '4M', '5M', '6M', '7M', '8M', '9M'] #Print lists in pixels #for i in range(len(textLst)): # print(textLst[i] + ' Centers (pixels) = ' + str(centerLst[i])) #Convert list of centers in pixels -> nm for i in range(len(centerLst)): for j in range(len(centerLst[i])): centerLst[i][j] = convertCenter2nm(centerLst[i][j], convtFact) #Print lists in nm #for i in range(len(textLst)): # print(textLst[i] + 'Centers (nm) = ' + str(centerLst[i])) #Program last three buttons loop3 = True while loop3: mousePress = win.getMouse() if exportButton.clicked(mousePress): #Export to xyz file (cords in Angstroms) if alertMessage('Export coordinates to xyz file \n saved as ringAnalyzerCoordinates.txt'): writeXYZ('ringAnalyzerCoordinates.txt', textLst, centerLst) exportButton.deactivate() else: exportButton.activate() elif distButton.clicked(mousePress): #PLOT atom / ring distribution plotDistribution(textLst, colorLst, centerLst) distButton.deactivate() elif quitButton.clicked(mousePress): if alertMessage('Click OK to exit the program \n (The image file will not be saved)'): win.close() loop3 = False else: quitButton.activate()
def createBoard(win): """Creates program boad & instructions""" #list of graphics positions, convert to fit monLen, monHeight, some vars gLen = [498, 498, 0, 498, 250, 250, 1000, 250, 175, 425, 1000, 250, 300, 400, 100, 100, 100, 100, 100, 100, 100, 350, 350, 350, 100] gLen = [(num / 500) * (monLen - 1000) for num in gLen] gHt = [0, 1000, 600, 600, 25, 625, 500, 75, 140, 140, 500, 190, 700, 700, 680, 750, 785, 820, 855, 890, 925, 845, 800, 900, 600] gHt = [monHeight * num / 1000 for num in gHt] #Create line diving instructions, toolbar, and image divideLine1 = graphics.Line(graphics.Point(monLen - 1000, gHt[0]), graphics.Point(monLen - 1000, gHt[1])) divideLine1.setWidth(2) divideLine1.draw(win) divideLine2 = graphics.Line(graphics.Point(gLen[2], gHt[2]), graphics.Point(gLen[3], gHt[3])) divideLine2.setWidth(2) divideLine2.draw(win) instructionLable = graphics.Text(graphics.Point(gLen[4], gHt[4]), 'Instructions') instructionLable.setSize(20) instructionLable.setStyle('italic') instructionLable.draw(win) toolLabel = graphics.Text(graphics.Point(gLen[5], gHt[5]), 'Toolbar') toolLabel.setSize(20) toolLabel.setStyle('italic') toolLabel.draw(win) imageLabel = graphics.Text(graphics.Point(gLen[6], gHt[6]), 'Upload Image Here') imageLabel.setSize(20) imageLabel.setStyle('italic') imageLabel.draw(win) #INSTRUCTIONS instruction1 = graphics.Text(graphics.Point(gLen[7], gHt[7]), "1.) Enter the name of the image file, then click ENTER. \ \n Note that the file must be saved as .png \n (ex. filename.png)") instruction1.draw(win) entry1 = graphics.Entry(graphics.Point(gLen[8], gHt[8]), 25) entry1.draw(win) enterButton1 = Button(win, graphics.Point(gLen[9], gHt[9]), 80, 20, '#52E643', 'ENTER') #Click enterButton, open the image, deactivate image loop = True while loop: if enterButton1.clicked(win.getMouse()): global imageName imageName = entry1.getText() #Check user imput for name of file if imageName != '' and imageName[-4:] == '.png': loop = False else: errorMessage('Please enter a PNG image file. \n (ex. filename.png)') enterButton1.activate() #Upload image into window myImage = graphics.Image(graphics.Point(monLen - 500, monHeight/2), imageName) myImage.draw(win) enterButton1.deactivate() instruction2 = graphics.Text(graphics.Point(gLen[11], gHt[11]), "2.) Click on the buttons below to place an atom or ring center. \ \n Double click to place the object on the image. \ \n Then click FINISH when all of the objects have been placed.") instruction2.draw(win) #Create TOOLBAR siButton = Button(win, graphics.Point(gLen[12], gHt[12]), 40, 25, '#1DAA43', 'Si') oButton = Button(win, graphics.Point(gLen[13], gHt[13]), 40, 25, '#FF1D0F', 'O') generalRing = Button(win, graphics.Point(gLen[14], gHt[14]), 140, 34, '#F8A61E', 'General Ring') button4MR = Button(win, graphics.Point(gLen[15], gHt[15]), 140, 22, '#9E4BF6', '4 Membered Ring') button5MR = Button(win, graphics.Point(gLen[16], gHt[16]), 140, 22, '#4BB0F6', '5 Membered Ring') button6MR = Button(win, graphics.Point(gLen[17], gHt[17]), 140, 22, '#43C47F', '6 Membered Ring') button7MR = Button(win, graphics.Point(gLen[18], gHt[18]), 140, 22, '#F9DE3E', '7 Membered Ring') button8MR = Button(win, graphics.Point(gLen[19], gHt[19]), 140, 22, '#F94C3E', '8 Membered Ring') button9MR = Button(win, graphics.Point(gLen[20], gHt[20]), 140, 22, '#F726E8', '9 Membered Ring') removeButton = Button(win, graphics.Point(gLen[21], gHt[21]), 100, 25, '#F96A61', 'REMOVE') doneButton = Button(win, graphics.Point(gLen[22], gHt[22]), 100, 25, '#41EFC9', 'DONE') finishButton = Button(win, graphics.Point(gLen[23], gHt[23]), 120, 30, '#D4FF33', 'FINISH') autoPlaceButton = Button(win, graphics.Point(gLen[24], gHt[24]), 140, 22, '#F8A61E', 'Auto Place') return [siButton, oButton, generalRing, button4MR, button5MR, button6MR, button7MR, button8MR, button9MR, autoPlaceButton, removeButton, finishButton, doneButton]
def plot_rainfall(): # input boxes input1 = g.Entry(g.Point(100, 50), 5) input1.draw(win) input2 = g.Entry(g.Point(200, 50), 5) input2.draw(win) input3 = g.Entry(g.Point(300, 50), 5) input3.draw(win) input4 = g.Entry(g.Point(400, 50), 5) input4.draw(win) input5 = g.Entry(g.Point(500, 50), 5) input5.draw(win) input6 = g.Entry(g.Point(600, 50), 5) input6.draw(win) input7 = g.Entry(g.Point(700, 50), 5) input7.draw(win) # input labels input_label1 = g.Text(g.Point(100, 25), "Day 1") input_label1.draw(win) input_label2 = g.Text(g.Point(200, 25), "Day 2") input_label2.draw(win) input_label3 = g.Text(g.Point(300, 25), "Day 3") input_label3.draw(win) input_label4 = g.Text(g.Point(400, 25), "Day 4") input_label4.draw(win) input_label5 = g.Text(g.Point(500, 25), "Day 5") input_label5.draw(win) input_label6 = g.Text(g.Point(600, 25), "Day 6") input_label6.draw(win) input_label7 = g.Text(g.Point(700, 25), "Day 7") input_label7.draw(win) # apply button button_apply = g.Rectangle(g.Point(800, 35), g.Point(875, 65)) button_apply.draw(win) text_apply = g.Text(g.Point(837, 50), "Apply") text_apply.draw(win) # axis lines line_y = g.Line(g.Point(50, 100), g.Point(50, 500)) line_y.draw(win) line_x = g.Line(g.Point(50, 500), g.Point(850, 500)) line_x.draw(win) # bars while 1 == 1: m = win.getMouse() if 800 <= m.getX() <= 875 and 35 <= m.getY() <= 65: bar1 = g.Rectangle(g.Point(50, 500), g.Point(150, 500 - int(input1.getText()))) bar1.draw(win) bar2 = g.Rectangle(g.Point(150, 500), g.Point(250, 500 - int(input2.getText()))) bar2.draw(win) bar3 = g.Rectangle(g.Point(250, 500), g.Point(350, 500 - int(input3.getText()))) bar3.draw(win) bar4 = g.Rectangle(g.Point(350, 500), g.Point(450, 500 - int(input4.getText()))) bar4.draw(win) bar5 = g.Rectangle(g.Point(450, 500), g.Point(550, 500 - int(input5.getText()))) bar5.draw(win) bar6 = g.Rectangle(g.Point(550, 500), g.Point(650, 500 - int(input6.getText()))) bar6.draw(win) bar7 = g.Rectangle(g.Point(650, 500), g.Point(750, 500 - int(input7.getText()))) bar7.draw(win)
def main(): windowName = "Anime Renaming Utility ~ (A.R.U.)" windowX = 400 windowY = 400 window = graphics.GraphWin(windowName, windowX, windowY) window.setBackground(graphics.color_rgb(17, 17, 29)) lineX = graphics.Line(graphics.Point(0, 280), graphics.Point(400, 280)) lineX.setFill("white") lineX.draw(window) lineY = graphics.Line(graphics.Point(130, 0), graphics.Point(130, 400)) lineY.setFill("white") lineY.draw(window) base_folder = os.path.dirname(__file__) left_path = os.path.join(base_folder, 'assets/leftarrow.gif') right_path = os.path.join(base_folder, 'assets/rightarrow.gif') nameLabel = graphics.Text(graphics.Point(60, 40), "Name:") nameControl = graphics.Entry(graphics.Point(260, 40), 25) seasonLabel = graphics.Text(graphics.Point(60, 100), "Season:") seasonControl = graphics.Entry(graphics.Point(160, 100), 3) episodesLabel = graphics.Text(graphics.Point(60, 160), "Episodes:") episodesControl = graphics.Entry(graphics.Point(160, 160), 3) startLabel = graphics.Text(graphics.Point(60, 220), "RENAME") startButton = graphics.Rectangle(graphics.Point(20, 205), graphics.Point(100, 235)) resultLabel = graphics.Text(graphics.Point(60, 340), "0 of 0:") resultControl = graphics.Entry(graphics.Point(260, 340), 25) leftButton = graphics.Rectangle(graphics.Point(5, 370), graphics.Point(30, 395)) rightButton = graphics.Rectangle(graphics.Point(100, 370), graphics.Point(125, 395)) leftLabel = graphics.Image(graphics.Point(17.5, 382.5), left_path) rightLabel = graphics.Image(graphics.Point(112.5, 382.5), right_path) nameLabel.setTextColor("white") nameControl.setFill("white") seasonLabel.setTextColor("white") seasonControl.setFill("white") episodesLabel.setTextColor("white") episodesControl.setFill("white") startLabel.setTextColor("white") startButton.setFill("green") resultLabel.setTextColor("white") resultControl.setText(' (^~^;)/ "Ready to go!"') leftButton.setFill(graphics.color_rgb(17, 17, 29)) rightButton.setFill(graphics.color_rgb(17, 17, 29)) leftButton.setOutline(graphics.color_rgb(17, 17, 29)) rightButton.setOutline(graphics.color_rgb(17, 17, 29)) seasonLabel.draw(window) seasonControl.draw(window) episodesLabel.draw(window) episodesControl.draw(window) startButton.draw(window) startLabel.draw(window) resultLabel.draw(window) resultControl.draw(window) nameLabel.draw(window) nameControl.draw(window) name = "" season = 0 episodes = 0 clearMode = False displayed = 0 while True: click = window.checkMouse() key = window.checkKey() if detect_start(startButton, click, key): if clearMode: nameControl.setText("") seasonControl.setText("") episodesControl.setText("") resultControl.setText("") displayed = 0 episodes = 0 resultLabel.setText(str(displayed) + " of " + str(episodes)) resultControl.setText(' (^~^;)/ "Ready to go!"') leftButton.undraw() rightButton.undraw() leftLabel.undraw() rightLabel.undraw() startButton.undraw() startLabel.undraw() startButton.setFill("green") startLabel.setText("RENAME") startButton.draw(window) startLabel.draw(window) clearMode = False else: startButton.undraw() startLabel.undraw() startButton.setFill("red") startLabel.setText("CLEAR") startButton.draw(window) startLabel.draw(window) leftButton.draw(window) rightButton.draw(window) leftLabel.draw(window) rightLabel.draw(window) name = nameControl.getText() season = seasonControl.getText() episodes = get_episodes(episodesControl) if int(episodes) > 0: displayed = displayed + 1 resultLabel.setText(str(displayed) + " of " + str(episodes)) clearMode = True if clearMode: if detect_left(leftButton, click, key) and displayed > 1: displayed = displayed - 1 elif detect_right(rightButton, click, key) and displayed < int(episodes): displayed = displayed + 1 if name == '' and season == '' and episodes == '0': resultControl.setText(' (o_o*) "Umm..."') elif name == '': resultControl.setText(' (~_~;) "Name, baka!"') elif episodes == '0': resultControl.setText(' (~_~;) "Episodes, baka!!"') else: result = format(name, season, displayed) resultLabel.setText(str(displayed) + " of " + str(episodes)) resultControl.setText(result) return
def draw_answerbox(): answerbox = gr.Entry(gr.Point(250, 280), 10) answerbox.setFill("#FFFFFF") answerbox.draw(window)
def showSettings(s): """Displays the settings menu, returns window and object list.""" lw = gr.GraphWin("Pysweeper | Settings",600,425,False) lw.setBackground(gr.color_rgb(33,33,33)) li = [] # 0: Top bar background # 1: Title BG # 2: Title FG # 3: Author name # 4: Window name li.append(gr.Rectangle(gr.Point(0, 0),gr.Point(600, 100))) li[0].setWidth(0) li[0].setFill(gr.color_rgb(66,66,66)) li.append(gr.Text(gr.Point(150,33),"PYSWEEPER")) li[1].setSize(26) li[1].setStyle("bold") li[1].setFill(gr.color_rgb(244,67,54)) li.append(gr.Text(gr.Point(150,33),"PYSWEEPER")) li[2].setSize(25) li[2].setStyle("bold") li[2].setFill(gr.color_rgb(250,250,250)) li.append(gr.Text(gr.Point(150,66),"By David S.")) li[3].setSize(20) li[3].setFill(gr.color_rgb(250,250,250)) li.append(gr.Text(gr.Point(450,50),"Settings")) li[4].setSize(30) li[4].setFill(gr.color_rgb(250,250,250)) li[4].setStyle("italic") li.append(gr.RoundedRectangle(gr.Point(25,125),gr.Point(287.5,200),25)) li[5].setFill(gr.color_rgb(33,33,33)) li[5].setOutline(gr.color_rgb(66,66,66)) li[5].setWidth(2) li.append(gr.RoundedRectangle(gr.Point(312.5,125),gr.Point(575,200),25)) li[6].setFill(gr.color_rgb(33,33,33)) li[6].setOutline(gr.color_rgb(66,66,66)) li[6].setWidth(2) li.append(gr.RoundedRectangle(gr.Point(25,225),gr.Point(475,300),25)) li[7].setFill(gr.color_rgb(33,33,33)) li[7].setOutline(gr.color_rgb(66,66,66)) li[7].setWidth(2) li.append(gr.RoundedRectangle(gr.Point(25,325),gr.Point(475,400),25)) li[8].setFill(gr.color_rgb(33,33,33)) li[8].setWidth(2) if s[3]: li[8].setOutline(gr.color_rgb(41,121,255)) li[8].setWidth(4) else: li[8].setOutline(gr.color_rgb(66,66,66)) li[8].setWidth(2) li.append(gr.RoundedRectangle(gr.Point(500,225),gr.Point(575,400),25)) li[9].setFill(gr.color_rgb(33,33,33)) li[9].setOutline(gr.color_rgb(66,66,66)) li[9].setWidth(2) li.append(gr.Text(gr.Point(75,162.5),"Width")) li[10].setSize(20) li[10].setFill(gr.color_rgb(250,250,250)) li.append(gr.Text(gr.Point(362.5,162.5),"Height")) li[11].setSize(20) li[11].setFill(gr.color_rgb(250,250,250)) li.append(gr.Text(gr.Point(150,262.5),"Number of mines")) li[12].setSize(20) li[12].setFill(gr.color_rgb(250,250,250)) li.append(gr.Text(gr.Point(150,362.5),"Hardcore mode")) li[13].setSize(20) li[13].setFill(gr.color_rgb(250,250,250)) li.append(gr.Text(gr.Point(537.5,225+(1*(175/5))),"S")) li[14].setSize(25) li[14].setFill(gr.color_rgb(250,250,250)) li[14].setStyle("bold") li.append(gr.Text(gr.Point(537.5,225+(2*(175/5))),"A")) li[15].setSize(25) li[15].setFill(gr.color_rgb(250,250,250)) li[15].setStyle("bold") li.append(gr.Text(gr.Point(537.5,225+(3*(175/5))),"V")) li[16].setSize(25) li[16].setFill(gr.color_rgb(250,250,250)) li[16].setStyle("bold") li.append(gr.Text(gr.Point(537.5,225+(4*(175/5))),"E")) li[17].setSize(25) li[17].setFill(gr.color_rgb(250,250,250)) li[17].setStyle("bold") li.append(gr.Entry(gr.Point(212.5,162.5),6)) li[18].setSize(15) li[18].setFill(gr.color_rgb(250,250,250)) li[18].setText(str(s[0])) li.append(gr.Entry(gr.Point(500,162.5),6)) li[19].setSize(15) li[19].setFill(gr.color_rgb(250,250,250)) li[19].setText(str(s[1])) li.append(gr.Entry(gr.Point(400,262.5),6)) li[20].setSize(15) li[20].setFill(gr.color_rgb(250,250,250)) li[20].setText(str(s[2])) li.append(gr.Image(gr.Point(400,362.5),"img/"+str(s[3])+".png")) for i in li: i.draw(lw) lw.flush() return lw,li
def render_initial_board(brd, score): ''' Clear terminal, print out board, and show current score. ''' span = range(len(brd)) gr_obs = dict() win = gr.GraphWin('Game Board', 500, 500, autoflush=False) gr_obs['win'] = win for i in span: for j in span: r = gr.Rectangle(gr.Point(10 + 70 * i, 10 + 70 * j), gr.Point(70 * (i + 1), 70 * (j + 1))) r.draw(win) t = gr.Text(gr.Point(460, 180), 'EXIT') t.setSize(24) t.setTextColor('red') t.draw(win) s = gr.Text(gr.Point(480, 490), score) s.setSize(18) s.setTextColor('blue') s.draw(win) gr_obs['score'] = s e = gr.Entry(gr.Point(250, 480), 5) e.draw(win) gr_obs['entry'] = e w = gr.Text(gr.Point(250, 450), '') w.draw(win) gr_obs['warning'] = w in_brd = [item for row in brd for item in row] brd_set = set(in_brd) brd_set.discard('.') for pce in brd_set: car_len = get_length(pce) pos = in_brd.index(pce) row = pos / 6 col = pos % 6 if (in_brd[pos + 1] == pce): c = gr.Rectangle(gr.Point(10 + 70 * col, 10 + 70 * row), gr.Point(70 * (col + car_len), 70 * (row + 1))) else: c = gr.Rectangle(gr.Point(10 + 70 * col, 10 + 70 * row), gr.Point(70 * (col + 1), 70 * (row + car_len))) if pce == 'X': c.setFill('red') elif car_len == 2: c.setFill('blue') else: c.setFill('green') l = gr.Text(c.getCenter(), pce) c.draw(win) l.draw(win) gr_obs[pce] = (c, l) win.update() return gr_obs
import graphics as g # import time # important stuff that needs to be accessed in different functions _close_ = g.Rectangle(g.Point(275, 0), g.Point(325, 50)) close_text = g.Text(g.Point(300, 25), 'Done') _close_.setFill('black') _roll_ = g.Rectangle(g.Point(275, 50), g.Point(325, 100)) roll_text = g.Text(g.Point(300, 75), 'Roll') _roll_.setFill(g.color_rgb(98, 166, 255)) _sim_ = g.Rectangle(g.Point(275, 100), g.Point(325, 150)) sim_text = g.Text(g.Point(300, 125), 'Sim') _sim_.setFill('blue') _res_ = g.Rectangle(g.Point(275, 150), g.Point(325, 200)) res_text = g.Text(g.Point(300, 175), 'Reset') _res_.setFill('red') inp = g.Entry(g.Point(-20, 0), 10) num_rolls = -1 perfect_rolls = -1 n_text = g.Text(g.Point(100, 420), 'Rolls: 0') p_text = g.Text(g.Point(100, 435), 'Five of a Kinds: 0') per_text = g.Text(g.Point(250, 435), '0%') draw_stuff = [_close_, close_text, _sim_, sim_text, _roll_, roll_text, inp, n_text, p_text, per_text, _res_, res_text] for _item_ in [close_text, roll_text, sim_text, res_text]: _item_.setStyle('bold') _item_.setFill('white') def main(): dice()
def spaceship(): #evaluates if bullets hit aliens score = 0 bullets = [] ufos = [] Shoot = "" spcshipSpeed = 10 timeshowaliens = 0 #creates games' window win = graphics.GraphWin('Spaceship Invasion', 800, 600) #set true for loop continu = "true" #draws score table score = 0 strscore = getScore() txtscoreRecord = graphics.Text(graphics.Point(80, 80), strscore) txtscoreRecord.draw(win) txtinstrunctions = graphics.Text(graphics.Point(200, 120), 'Click to start Playing') txtinstrunctions.draw(win) txtscore = graphics.Text(graphics.Point(70, 20), "Enter Your Name: ") txtscore.draw(win) nameinput = graphics.Entry(graphics.Point(250, 20), 25) nameinput.draw(win) x = graphics.GraphWin.getMouse(win) getname = nameinput.getText() nameinput.undraw() txtscoreRecord.undraw() txtinstrunctions.undraw() txt = "Score:", score txtscore.setText(txt) #Creates first alien img = graphics.Image(graphics.Point(90, 550), "spaceship.png") img.draw(win) showaliensrdm = random.randint(1, 10) #Controls for spaceship movement while continu == 'true': #increase time for aliens attack when score is more than 10 #checks keyboard string = win.checkKey() #moves spaceship to left imgpoint = img.getAnchor() imgpointx = imgpoint.getX() imgpointy = imgpoint.getY() if string == 'Left': if imgpointx > 60: img.move(-spcshipSpeed, 0) #moves spaceship to right elif string == 'Right': if imgpointx < 740: img.move(spcshipSpeed, 0) #Shoots bullets elif string == 'space': if len(bullets) < 5: Shoot = Bullet(graphics.Point(imgpointx, imgpointy - 60), graphics.Point(imgpointx, imgpointy - 70)) Shoot.setWidth(3) bullets.append(Shoot) Shoot.draw(win) #Plays shoot sound winsound.PlaySound('shoot.wav', winsound.SND_ASYNC) #to quit game elif string == 'q': message = graphics.Text(graphics.Point(win.getWidth() / 2, 20), 'Click anywhere to quit.') message.draw(win) continu = "false" #Moves bullets if there are bullets shot if bullets: for i in bullets: i.move(0, -2) bulletsPoint = i.getP1() bulletsy = bulletsPoint.getY() #Deletes bullets when screen edge is reached if bulletsy < 0: i.undraw() bullets.remove(i) cllsn = collision(bullets, ufos) score = score + int(cllsn) #updates score txt = "Score:", score txtscore.setText(txt) #shows aliens if timeshowaliens == showaliensrdm: #shows maximun of 10 aliens at a time if len(ufos) < 10: randomx = random.randint(60, 740) randomy = random.randint(20, 30) newufo = ufo(graphics.Point(randomx, randomy), "alienufo.png") newufo.draw(win) ufos.append(newufo) ufos[len(ufos) - 1].speed = random.randint(1, 2) if score < 10: showaliensrdm = random.randint(300, 400) elif score < 15: showaliensrdm = random.randint(200, 300) elif score < 20: showaliensrdm = random.randint(150, 200) else: showaliensrdm = random.randint(125, 150) timeshowaliens = 0 else: timeshowaliens = timeshowaliens + 1 #moves aliens if there are aliens if ufos: for x in ufos: #ufospeed= #print(ufospeed) x.move(0, x.speed) imgpoint = x.getAnchor() imgpointy = imgpoint.getY() #undraws ufos if screen edge is reached if imgpointy > 560: x.undraw() ufos.remove(x) score = score - 1 txt = "Score:", score txtscore.setText(txt) #Delays update of canvas graphics.time.sleep(.008) win.update() writeScore(score, getname) win.getMouse() win.close()
BAR_INSET = 5 WINDOW_HEIGHT = GRAPH_HEIGHT + 2 * TEXT_HEIGHT win = g.GraphWin("Sales Bar Grapher", GRAPH_WIDTH + 2 * HORIZONTAL_MARGIN, WINDOW_HEIGHT) labelPoint = g.Point(50, TEXT_HEIGHT / 2) entryPoint = labelPoint.clone() entryPoint.move(75, 0) salesEntryLabel = g.Text(labelPoint, "Enter Sales:") salesEntryLabel.draw(win) salesEntry = g.Entry(entryPoint, 5) salesEntry.draw(win) topAxisPoint = g.Point(HORIZONTAL_MARGIN, TEXT_HEIGHT) bottomAxisPoint = g.Point(HORIZONTAL_MARGIN, WINDOW_HEIGHT - TEXT_HEIGHT) axisLine = g.Line(topAxisPoint, bottomAxisPoint) axisLine.draw(win) totalSales = 0 for dayOfSales in range(3): win.getMouse() nextSales = int(salesEntry.getText()) topLeftRectPoint = topAxisPoint.clone() topLeftRectPoint.move(totalSales, BAR_INSET)