def main() : # Introduction print ( " This program plots the growth of a 10-year investment . " ) # Get principal and interest rate principal = float(input ("Enter the initial principal : ")) apr = float(input("Enter the annualized interest rate : ")) # Create a graphics window with labels on left edge win = GraphWin ("Investment Growth Chart ", 320 , 240) win.setBackground ("white") win.setCoords (-1.75, -200 , 11.5, 10400) Text(Point (- 1, 0) , ' 0.0K').draw (win) Text(Point (- 1, 2500) , '2.5K').draw (win) Text(Point (- 1, 5000) , ' 5.0K').draw (win) Text(Point (- 1, 7500) , ' 7.5k').draw (win) Text(Point (- 1, 10000) , '10.0K').draw (win) # Draw bar f or init ial princ ipal bar = Rectangle (Point (0, 0) , Point (1, principal)) bar.setFill ("green") bar.setWidth (2) bar.draw (win) # Draw a bar for each subsequent year for year in range (1, 11) : principal = principal * ( 1 + apr) bar = Rectangle (Point (year, 0), Point (year+ 1 , principal )) bar.setFill ("green") bar.setWidth (2) bar.draw(win) input(" Press <Enter> to quit.") win.close ()
def game_over(winner): center = Point(WIN.getWidth() / 2, WIN.getHeight() / 2) if winner == "human": game_over_text = Text(center, "Game Over!") thanks_text = Text( center, " \n\n\n\n\nCongratulations you won!\n\n" + "Click to play again otherwise this window will" + " terminate in 10 seconds") style_text(game_over_text) style_text(thanks_text) game_over_text.setSize(36) thanks_text.setTextColor("green") game_over_text.setTextColor("green") thanks_text.setTextColor("green") game_over_text.draw(WIN) thanks_text.draw(WIN) elif winner == "ai": game_over_text = Text(center, "Game Over!") thanks_text = Text( center, " \n\n\n\n\nYou lost!\n\n" + "Click to play again otherwise this window" + " will terminate in 10 seconds") style_text(game_over_text) game_over_text.setSize(36) style_text(thanks_text) thanks_text.setTextColor("red") game_over_text.setTextColor("red") thanks_text.setTextColor("red") game_over_text.draw(WIN) thanks_text.draw(WIN)
def main(): win = GraphWin("House", 600, 600) win.setCoords(0,0,600,600) Text(Point(300,10),"5 Click House").draw(win) # Draw the main house p1 = win.getMouse() p2 = win.getMouse() Rectangle(p1, p2).draw(win) # Draw the door con = (abs(p1.x) - (p2.x)) / 5 p3 = win.getMouse() d1 = Point(p3.x + con / 2, p3.y) d2 = Point(p3.x - con / 2, p1.y) Rectangle(d1, d2).draw(win) # Draw the window p4 = win.getMouse() w1 = Point(p4.x - con / 4, p4.y + con / 4) w2 = Point(p4.x + con / 4, p4.y - con / 4) Rectangle(w1, w2).draw(win) p5 = win.getMouse() Polygon(p2, Point(p1.x, p2.y), p5).draw(win) Text(Point(300,590),"I hoped you liked my house!!").draw(win) time.sleep(10) # sleep the thread for 10 seconds
def drawGamePanel(): # Creates gray Game Panel window game_panel = GraphWin("Game Panel", 300, 300) game_panel.setBackground("gray") # Creates title text with background title_background = Rectangle(Point(0, 0), Point(300, 40)) title_background.setFill("white") title_background.draw(game_panel) title_text = Text(Point(150, 20), "BoilerMazer") title_text.setSize(30) title_text.setStyle("bold") title_text.draw(game_panel) # Creates exit button and text exit_button = Rectangle(Point(250, 260), Point(300, 300)) exit_button.setFill("red") exit_button.draw(game_panel) exit_text = Text(Point(275, 281), "EXIT") exit_text.setSize(14) exit_text.draw(game_panel) # Creates green button, which will be used for new player and start options green_button = Rectangle(Point(100, 260), Point(200, 300)) green_button.setFill("green") green_button.draw(game_panel) return game_panel
def ten_strings(): """ 7. Write a function, ten_strings(), that allows the user to plot 10 strings of their choice at locations of a graphics window chosen by clicking on the mouse (the strings should be entered one-by-one by the user within a text entry box at the top of the graphics window, clicking the mouse after entering each one). """ win = GraphWin("Ten strings", 400, 300) message = Text(Point(200, 15), "Enter what you want then click where you want it") message.draw(win) input_box = Entry(Point(200, 50), 10) input_box.draw(win) for _ in range(10): position = win.getMouse() if input_box.getText() == "": new_message = Text(position, "[EMPTY MESSAGE]") else: new_message = Text(position, input_box.getText()) new_message.draw(win) input_box.setText("") message.setText("You have used up all of your messages") await_user_input(win)
def __init__(self): self.win = GraphWin("Dice Poker", 600, 400) self.win.setBackground("green3") banner = Text(Point(300, 30), "Python Poker Parlor") banner.setSize(24) banner.setFill("yellow2") banner.setStyle("bold") banner.draw(self.win) self.msg = Text(Point(300, 380), "Welcome to the Dice Table") self.msg.setSize(18) self.msg.draw(self.win) self.createDice(Point(300, 100), 75) self.buttons = [] self.addDiceButtons(Point(300, 170), 75, 30) b = Button(self.win, Point(300, 230), 400, 40, "Roll Dice") self.buttons.append(b) b = Button(self.win, Point(300, 280), 150, 40, "Score") self.buttons.append(b) b = Button(self.win, Point(570, 375), 40, 30, "Quit") self.buttons.append(b) b = Button(self.win, Point(30, 375), 40, 30, "Help") self.buttons.append(b) self.money = Text(Point(300, 325), "$100") self.money.setSize(18) self.money.draw(self.win)
def __init__(self): super().__init__("Roll for your life!", self.WINDOW_WIDTH, self.WINDOW_HEIGHT) self.setBackground(self.WINDOW_BACKGROUND) width = self.getWidth() height = self.getHeight() self.diePanel1 = DicePanel(self, Point(0, 0), Point(width, height // 2), self.PLAYER_BACKGROUND) self.diePanel2 = DicePanel(self, Point(0, height // 2), Point(width, height), background=self.NPC_BACKGROUND) self.rollButton = Button(self, Point(width - 80, 30), 80, 30, "Roll") self.rollButton.activate() self.quitButton = Button(self, Point(width - 80, height / 2 - 40), 80, 30, "Close") self.npcText = Text(Point(width // 2, 3 * height // 4), "NPC Score") self.npcText.setFill(self.NPC_FOREGROUND) self.npcText.setSize(36) self.playerText = Text(Point(width // 2, height // 4), "Player Score") self.playerText.setFill(self.PLAYER_FOREGROUND) self.playerText.setSize(36)
def main(): print("This program plots the growth of a 10-year investment!") principal = eval(input("Enter the initial principal: ")) apr = eval(input("Enter the annualized interest rate: ")) win = GraphWin("Investment Growth Chart", 320, 240) win.setBackground("white") win.setCoords(-1.75, -200, 11.5, 10400) Text(Point(-1, 0), "0.0K").draw(win) Text(Point(-1, 2500), "2.5K").draw(win) Text(Point(-1, 5000), "5.0K").draw(win) Text(Point(-1, 7500), "7.5K").draw(win) Text(Point(-1, 10000), "10.0K").draw(win) bar = Rectangle(Point(0, 0), Point(1, principal)) bar.setFill("green") bar.setWidth(2) bar.draw(win) for year in range(1, 11): principal = principal * (1 + apr) bar = Rectangle(Point(year, 0), Point(year + 1, principal)) bar.setFill("green") bar.setWidth(2) bar.draw(win) input("Press <Enter> to quit.") win.close()
def main(): # Introduction print("This program plots the growth of a 10-year investment.") # Get principal and interest rate principal = float(input(" Enter the initial principal: ")) apr = float(input(" Enter the annualized interest rate: ")) # Create a graphics window with labels on left edge win = GraphWin("Investment Growth Chart ", 320, 240) win.setBackground("white") Text(Point(20, 230), ' 0.0K').draw(win) Text(Point(20, 180), ' 2.5K').draw(win) Text(Point(20, 130), ' 5.0K').draw(win) Text(Point(20, 80), ' 7.5K').draw(win) Text(Point(20, 30), '10.0K').draw(win) # Draw bar for initial principal height = principal * 0.02 bar = Rectangle(Point(40, 230), Point(65, 230 - height)) bar.setFill("green") bar.setWidth(2) bar.draw(win) # Draw bars for successive years for year in range(1, 11): # calculate value for the next year principal = principal * (1 + apr) # draw bar for this value xll = year * 25 + 40 height = principal * 0.02 bar = Rectangle(Point(xll, 230), Point(xll + 25, 230 - height)) bar.setFill("green") bar.setWidth(2) bar.draw(win) input(" Press <Enter> to quit ") win.close()
def __create_window(self): for row in range(self.__dimension[1]): for coll in range(self.__dimension[0]): cell_position = (OFFSET + CELL_DIMENSION[0] * coll, OFFSET + CELL_DIMENSION[1] * row) if row == 0 or row == self.__dimension[1] - 1 or coll == 0 or coll == self.__dimension[0] - 1 or\ (coll == 15 and row < 18) or (coll == 32 and row > 13): cell_type = WALL cell = Cell(pos=cell_position, cell_type=cell_type, win=self.__win, cell_pos=(coll, row), color=BLOCK_COLOR) else: cell_type = EMPTY cell = Cell(pos=cell_position, cell_type=cell_type, win=self.__win, cell_pos=(coll, row)) cell.draw() self.__cells.append(cell) self.__day_counter = Text( Point(150, OFFSET + CELL_DIMENSION[1] * (self.__dimension[1] + 2)), f"Day: {self.__day}") self.__day_counter.draw(self.__win) self.__generation_counter = Text( Point(OFFSET + CELL_DIMENSION[0] * self.__dimension[0] - 100, OFFSET + CELL_DIMENSION[1] * (self.__dimension[1] + 2)), f"Generation: {self.__generation}") self.__generation_counter.draw(self.__win) self.__bot_counter = Text( Point(OFFSET + CELL_DIMENSION[0] * self.__dimension[0] - 375, OFFSET + CELL_DIMENSION[1] * (self.__dimension[1] + 2)), f"Bots count: {len(self.__bots)}") self.__bot_counter.draw(self.__win) text = Text( Point( OFFSET + self.__dimension[0] * CELL_DIMENSION[0] + 2 * OFFSET, OFFSET), "Last generation duration:").draw(self.__win) text.setSize(18) for i in range(10): text = Text( Point( OFFSET + self.__dimension[0] * CELL_DIMENSION[0] + 2 * OFFSET, OFFSET + 2 * CELL_DIMENSION[0] * (i + 1)), "") text.draw(self.__win) self.__try_texts.append(text)
def frame(self, win, s): header = Text(Point(350, 650), s) header.draw(win) for i in range(6): line = Line(Point(0, (i + 1) * 100), Point(700, (i + 1) * 100)) line.draw(win) for i in range(7): horizontal = Line(Point((i + 1) * 100, 600), Point((i + 1) * 100, 0)) horizontal.draw(win) for i in range(7): day = Text(Point((i * 100) + 50, 625), self.weekDays.get(i)) day.draw(win)
def window(): win = GraphWin("얘기 카운트", 1280, 720) win.setBackground(color_rgb(17, 22, 15)) historyText = Text(Point(480, 360), '') historyText.setFill(color_rgb(255, 255, 255)) historyText.setFace("arial") historyText.setSize(16) historyText.draw(win) rect = Rectangle(Point(960, 0), Point(1280, 720)) rect.setFill(color_rgb(17, 22, 15)) rect.draw(win) clockText = Text(Point(1117, 16), "") clockText.setFill(color_rgb(255, 255, 255)) clockText.setFace("courier") clockText.setSize(16) clockText.draw(win) yaegiConstText = Text(Point(1117, 300), "%s 횟수" % toFilter) yaegiConstText.setFill(color_rgb(255, 255, 255)) yaegiConstText.setFace("arial") yaegiConstText.setSize(36) yaegiConstText.draw(win) yaegiNumberText = Text(Point(1117, 420), "0") yaegiNumberText.setFill(color_rgb(255, 255, 255)) yaegiNumberText.setFace("arial") yaegiNumberText.setSize(36) yaegiNumberText.draw(win) line = graphics.Line(Point(960, 0), Point(960, 720)) line.setFill(color_rgb(200, 200, 200)) line.draw(win) while not win.checkMouse(): clockText.setText( "%s KST" % datetime.datetime(2020, 1, 1).now().isoformat().split('.')[0]) yaegiNumberText.setText(str(yaegiCount)) historyText.setText('\n'.join(history)) sleep(1) win.close() running = False global f f.write('%s count: %d' % (toFilter, yaegiCount))
def begin(): #Ready? Text begText1 = Text(Point(25,20), "Ready?") begText1.setFace("times roman") begText1.draw(win) sleep(1.5) begText1.undraw() sleep(0.5) #"Here's a point" Text and Plotting first point begText2 = Text(Point(25,20), "Here's a point.") begText2.setFace("times roman") begText2.draw(win) point1 = Point(25,25) point1.draw(win) sleep(1.5) begText2.undraw() sleep(0.5) #moving First point clickAnywhere = Text(Point(25, 20), "Press 'l' or 'r' to move the point off the screen in either direction.") clickAnywhere.setFace("times roman") clickAnywhere.draw(win) #win.getMouse() key = win.getKey() clickAnywhere.undraw() if key == "r": for i in range(55): point1.move(.5,0) sleep(0.05) if key == "l": for i in range(55): point1.move(-.5,0) sleep(0.05) point1.undraw() #First Congrats Text and Transition greatxt = Text(Point(25,20), "Great!") greatxt.setFace("times roman") greatxt.draw(win) sleep(1.5) greatxt.undraw() tranText = Text(Point(25,20), "Now, click your mouse on the window to create a red circle") tranText.setFace("times roman") tranText.draw(win) win.getMouse() tranText.undraw() #call to next function drawCircle()
def drawData(self, win, year, month): # year, month are the user requested date file = open("RunningDatabase.txt", "r") f = file.readlines() monthDayStart = calendar().monthStartDay(year, month) for i in range(len(f)): line = f[i].split(",") fileYear = int(line[2].replace(")", "")) fileMonth = int(line[0].replace("(", "")) fileDay = int(line[1]) fileDate = [fileYear, fileMonth, fileDay] if (fileYear == year and fileMonth == month): numDays = calendar().leapYearException(year, month) for k in range(numDays): if (fileDay == k): if (k + monthDayStart <= 7): for j in range(3): data = Text( Point((k - 1) * 100 + 50, 575 - (j * 25)), line[j + 3]) data.draw(win) if (k + monthDayStart > 7 and k + monthDayStart <= 14): for j in range(3): data = Text( Point((k - 8) * 100 + 50, 475 - (j * 25)), line[j + 3]) data.draw(win) if (k + monthDayStart > 14 and k + monthDayStart <= 21): for j in range(3): data = Text( Point((k - 15) * 100 + 50, 375 - (j * 25)), line[j + 3]) data.draw(win) if (k + monthDayStart > 21 and k + monthDayStart <= 28): for j in range(3): data = Text( Point((k - 22) * 100 + 50, 275 - (j * 25)), line[j + 3]) if (k + monthDayStart > 28 and k + monthDayStart <= 37): for j in range(3): data = Text( Point((k - 29) * 100 + 50, 175 - (j * 25)), line[j + 3])
def main(): # create the application window win = GraphWin("Dice Poker", WINDOW_WIDTH, WINDOW_HEIGHT) win.setBackground("black") # draw the interface widgets centerPoint = Point(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) quit = Button(win, Point(WINDOW_WIDTH - 50, WINDOW_HEIGHT - 50), 75, 50, 'Quit') quit.activate() roll = Button(win, Point(WINDOW_WIDTH - 125, WINDOW_HEIGHT - 50), 75, 50, 'Roll') roll.activate() m = (WINDOW_WIDTH / 5) + (5*25) for k in range(5): hand.append(DieView(win, Point(WINDOW_WIDTH / 2 - m, WINDOW_HEIGHT / 2), 100)) m -= 125 scoreText = Text(Point(50, 50), "Score Text Goes Here...") scoreText.setTextColor("white") scoreText.draw(win) global helpText helpText = Text(Point(WINDOW_WIDTH - 200, 75), "Help Text Goes Here...") helpText.setTextColor("white") helpText.draw(win) playHand() # event loop run = True while run: updateScore(scoreText) clickPoint = win.getMouse() if (roll.clicked(clickPoint)): playHand() run = ( (not quit.clicked(clickPoint)) and (playerAmount >= 10) ) updateScore(scoreText) # By now, player has exhausted funds if (playerAmount <= 10): helpText.setText(helpText.getText() + "\nYou've don't have enough for another roll.") roll.deactivate() while (not quit.clicked(clickPoint)): # Wait till the user clicks quit clickPoint = win.getMouse() # close the window win.close()