{"id":13358,"date":"2023-08-18T15:22:00","date_gmt":"2023-08-18T13:22:00","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=13358"},"modified":"2023-09-17T20:29:12","modified_gmt":"2023-09-17T18:29:12","slug":"button-widget-in-pygame-updated","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/button-widget-in-pygame-updated\/","title":{"rendered":"Button widget in Pygame updated"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/button_live_coding_1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"796\" height=\"873\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/button_live_coding_1.png\" alt=\"\" class=\"wp-image-13486\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/button_live_coding_1.png 796w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/button_live_coding_1-320x351.png 320w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/button_live_coding_1-768x842.png 768w\" sizes=\"auto, (max-width: 796px) 100vw, 796px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I made some changes to this code to add a command to every button in an easy way: adding a parameter as argument of the class Button that contains the function that does what that button is made for.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the code. If you do not provide a function as argument, there will be a warning telling you how to do it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you run the script you get these buttons. They looks pretty and when you mouseover them they change the color. Ok, now let&#8217;s see what happens when we click the buttons (only the first one got the bind to the command function.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-113.png\"><img loading=\"lazy\" decoding=\"async\" width=\"503\" height=\"538\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-113.png\" alt=\"\" class=\"wp-image-13360\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-113.png 503w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-113-320x342.png 320w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here is what happens when you press the 3 button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first one has the parameter (command1) to link it to the function command1. This function has the code to change the text of the button, from rome to pressed and also prints something on the terminal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you press the other 2, you get the warning, because they haven&#8217; assigned a function yet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pretty \ud83d\ude0e, ah?<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-112.png\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"561\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-112-960x561.png\" alt=\"\" class=\"wp-image-13359\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-112-960x561.png 960w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-112-320x187.png 320w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-112-768x449.png 768w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-112.png 1014w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">The bind method<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I was thinking&#8230; why don&#8217;t add a binding method, alternative to passing the function as argument? Said and done. here is how you can bind the second button, for example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">button3.bind(lambda: print(\"Hello\"))<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is alternative to the other method. You can alway also do:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">button2.command = (lambda: print(\"I am Milan button\"))<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The result will be the same, but this way you can add or change the command even after the istanciation of the widget.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame, sys\n\n\n\ndef help_empty_command():\n\t''' function for buttons without command argument '''\n\tprint(f\"\"\"\n\t\t[WARNING]:\n\t\t\tYou have not assigned a function to\n\t \t\tyour button. Create a function called command2, for\n\t  \t\texample and add command2 as last parameter of the istance\n\t   \t\tof this buttonex:\n\t   \t\tbutton1 = Button('Rome',200,40,(100,200),5, command1))\"\"\")\n\nbuttons = []\nclass Button:\n\tdef __init__(self,text,width,height,pos,elevation, command=help_empty_command):\n\t\t#Core attributes \n\t\tself.pressed = False\n\t\tself.elevation = elevation\n\t\tself.dynamic_elecation = elevation\n\t\tself.original_y_pos = pos[1]\n\t\tself.command = command\n\n\t\t# top rectangle \n\t\tself.top_rect = pygame.Rect(pos,(width,height))\n\t\tself.top_color = '#475F77'\n\n\t\t# bottom rectangle \n\t\tself.bottom_rect = pygame.Rect(pos,(width,height))\n\t\tself.bottom_color = '#354B5E'\n\t\t#text\n\t\tself.text = text\n\t\tself.text_surf = gui_font.render(text,True,'#FFFFFF')\n\t\tself.text_rect = self.text_surf.get_rect(center = self.top_rect.center)\n\t\tbuttons.append(self)\n\n\tdef change_text(self, newtext):\n\t\tself.text_surf = gui_font.render(newtext, True,'#FFFFFF')\n\t\tself.text_rect = self.text_surf.get_rect(center = self.top_rect.center)\n\n\tdef bind(self, command):\n\t\tself.command = command\n\n\tdef draw(self):\n\t\t# elevation logic \n\t\tself.top_rect.y = self.original_y_pos - self.dynamic_elecation\n\t\tself.text_rect.center = self.top_rect.center \n\n\t\tself.bottom_rect.midtop = self.top_rect.midtop\n\t\tself.bottom_rect.height = self.top_rect.height + self.dynamic_elecation\n\n\t\tpygame.draw.rect(screen,self.bottom_color, self.bottom_rect,border_radius = 12)\n\t\tpygame.draw.rect(screen,self.top_color, self.top_rect,border_radius = 12)\n\t\tscreen.blit(self.text_surf, self.text_rect)\n\t\tself.check_click()\n\n\tdef check_click(self):\n\t\tmouse_pos = pygame.mouse.get_pos()\n\t\tif self.top_rect.collidepoint(mouse_pos):\n\t\t\tself.top_color = '#D74B4B'\n\t\t\tif pygame.mouse.get_pressed()[0]:\n\t\t\t\tself.dynamic_elecation = 0\n\t\t\t\tself.pressed = True\n\t\t\t\tself.change_text(f\"{self.text}\")\n\t\t\telse:\n\t\t\t\tself.dynamic_elecation = self.elevation\n\t\t\t\tif self.pressed == True:\n\t\t\t\t\tself.command()\n\t\t\t\t\tself.pressed = False\n\t\t\t\t\tself.change_text(self.text)\n\t\telse:\n\t\t\tself.dynamic_elecation = self.elevation\n\t\t\tself.top_color = '#475F77'\n\n\n\ndef command1():\n\tprint(\"The first button has some code\")\n\tbutton1.text = \"Pressed\"\n\n\npygame.init()\nscreen = pygame.display.set_mode((500,500))\npygame.display.set_caption('Gui Menu')\nclock = pygame.time.Clock()\ngui_font = pygame.font.Font(None,30)\n\nbutton1 = Button('Rome',200,40,(100,200),5, command1)\nbutton2 = Button('Milan',200,40,(100,250),5)\nbutton2.command = (lambda: print(\"I am Milan button\"))\nbutton3 = Button('Neaples',200,40,(100,300),5)\nbutton3.bind(lambda: print(\"Hello\"))\n\n\n\ndef buttons_draw():\n\tfor b in buttons:\n\t\tb.draw()\n\nwhile True:\n\tfor event in pygame.event.get():\n\t\tif event.type == pygame.QUIT:\n\t\t\tpygame.quit()\n\t\t\tsys.exit()\n\n\tscreen.fill('#DCDDD8')\n\tbuttons_draw()\n\n\tpygame.display.update()\n\tclock.tick(60)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">The repository<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/formazione\/pygame_button\">https:\/\/github.com\/formazione\/pygame_button<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/formazione\/pygame_widgets\">https:\/\/github.com\/formazione\/pygame_widgets<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A button using only surfaces and the class Sprite<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pygame\n\n\nscreen = pygame.display.set_mode((800, 600))\nbuttons = pygame.sprite.Group()\nclass Button(pygame.sprite.Sprite):\n    ''' Create a button clickable with changing hover color'''\n\n    def __init__(self, text=\"Click\",\n                pos=(0,0), fontsize=16,\n                colors=\"white on blue\", hover_colors=\"red on green\",\n                command=lambda: print(\"No command activated for this button\")):\n\n        super().__init__()\n        self.text = text\n        self.command = command\n        self.colors = colors\n        self.original_colors = colors\n        self.fg, self.bg = self.colors.split(\" on \")\n        self.fgh, self.bgh = hover_colors.split(\" on \")\n        self.font = pygame.font.SysFont(\"Arial\", fontsize)\n        self.pos = pos\n        self.create_original()\n        self.create_hover_image()\n\n    def create_original(self):\n        self.image = self.create_bg(self.text, self.fg, self.bg)\n        self.original_image = self.image.copy()\n\n\n    def create_hover_image(self):\n        self.hover_image = self.create_bg(self.text, self.fgh, self.bgh)\n        self.pressed = 1\n        buttons.add(self)\n\n\n    def create_bg(self, text, fg, bg):\n        self.text = text\n        image = self.font.render(self.text, 1, fg)\n        self.rect = image.get_rect()\n        self.rect.x, self.rect.y = self.pos\n        bgo = pygame.Surface((self.rect.w, self.rect.h))\n        bgo.fill(bg)\n        bgo.blit(image, (0,0))\n        return bgo\n\n\n    def update(self):\n        ''' CHECK IF HOVER AND IF CLICK THE BUTTON '''\n        if self.rect.collidepoint(pygame.mouse.get_pos()):\n            self.image = self.hover_image\n            self.check_if_click()\n        else:\n            self.image = self.original_image\n\n\n    def check_if_click(self):\n        ''' checks if you click on the button and makes the call to the action just one time'''\n        if self.rect.collidepoint(pygame.mouse.get_pos()):\n            if pygame.mouse.get_pressed()[0] and self.pressed == 1:\n                # print(\"Execunting code for button '\" + self.text + \"'\")\n                self.command()\n                self.pressed = 0\n            if pygame.mouse.get_pressed() == (0,0,0):\n                self.pressed = 1\n\n\nif __name__ == \"__main__\":\n# Hello, this is a snippet\n\n    pygame.init()\n\n    pygame.display.set_caption('Example of button')\n    screen = pygame.display.set_mode((1000, 800))\n    clock = pygame.time.Clock()\n\n    def window():\n        b1 = Button(\"CLICK ME\", pos=(100,100),\n            fontsize=36,\n            colors=\"red on green\",\n            hover_colors=\"green on red\",\n            command=lambda: print(\"clicked right now\"))\n\n\n    window()\n\n\n    is_running = True\n    while is_running:\n\n        for event in pygame.event.get():\n         if event.type == pygame.QUIT:\n             is_running = False\n\n        # to show buttons created\n        buttons.update()\n        buttons.draw(screen)\n\n        pygame.display.update()\n        clock.tick(60)\n\n    pygame.quit()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The old post<\/h2>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-python-programming wp-block-embed-python-programming\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"hGy6rfjpoY\"><a href=\"https:\/\/pythonprogramming.altervista.org\/buttons-in-pygame\/\">How to make Buttons in pygame<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;How to make Buttons in pygame&#8221; &#8212; python programming\" src=\"https:\/\/pythonprogramming.altervista.org\/buttons-in-pygame\/embed\/#?secret=G3Omsv2GjO#?secret=hGy6rfjpoY\" data-secret=\"hGy6rfjpoY\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><!-- se vuoi mettere un testo scorrevole\r\n[hoops name=\"typeWriterGen\"]\r\n\r\npoi metti un id diverso per ogni testo nella stessa pagina\r\n\r\n<div id=\"div01\">\r\n<script>\r\n\r\ntypeWriterGen(\"div01\",\"Esempio di testo scorrevole\");\r\n<\/script>\r\n\r\n-->\r\n<style>\r\n.avatar {\r\n  vertical-align: middle;\r\n  width: 100px;\r\n  height: 100px;\r\n  border-radius: 50%;\r\n}\r\n<\/style>\r\n\r\n<hr>\r\n\r\n<!-- NEWSLETTER LINK -->\r\n<a href=\"https:\/\/docs.google.com\/forms\/d\/e\/1FAIpQLSf7TniIPCWHDzCSGh2dYZaCwDvi9yLKS5ovFdKuK1sdfOvwEg\/viewform\">\r\n<img decoding=\"async\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/08\/image-13.png\" class=\"avatar\">\r\nSubscribe to the <b>newsletter<\/b> for updates<\/a><br>\r\n\r\n<!-- TKINTER TEMPLATE LINK -->\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/tkinter-templates\/\">\r\n<img decoding=\"async\" src=\"https:\/\/i0.wp.com\/pythonprogramming.altervista.org\/wp-content\/uploads\/2023\/07\/image-26.png\" class=\"avatar\">\r\nTkinter templates<\/a><br>\r\n\r\n<!-- MY AVATAR PUT A LINK TO YOUTUBE CHANNEL-->\r\n<iframe loading=\"lazy\" frameborder=\"0\" src=\"https:\/\/itch.io\/embed\/711828\" width=\"552\" height=\"167\"><a href=\"https:\/\/pythonprogrammi.itch.io\/pysnake\">PySnake by PythonProgrammi<\/a><\/iframe>\r\n<br>\r\n<style>\r\n.avatar {\r\n  vertical-align: middle;\r\n  width: 100px;\r\n  height: 100px;\r\n  border-radius: 50%;\r\n}\r\n<\/style>\r\n\r\n\r\n<a href=\"https:\/\/www.youtube.com\/channel\/UCzbxq5e9gLiY-je2-br1rvg\">\r\n\t<img decoding=\"async\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/10\/avatar64x64.png\" alt=\"Avatar\" class=\"avatar\">\r\n\t My youtube channel<\/a><br>\r\n\r\n<br>\r\n\r\nTwitter: <a href=\"https:\/\/twitter.com\/pythonprogrammi\">@pythonprogrammi - python_pygame<\/a>\r\n<h3>Claude's Games<\/h3>\r\n<p><a href=\"https:\/\/pythonprogramming.altervista.org\/random-daily-game-1-arkanoid\/\">Arkanoid<\/a><br>\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/platform-2d-with-pygame-made-with-claude\/\">Platform 2d<\/a><\/p> <!-- videogames made with claude -->\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/artifacts-games-day-1-memory-game\/\">1. Memory game<\/a>\r\n<h4>Videos<\/h4>\r\n<a href=\"https:\/\/youtu.be\/ciLjWWw5pLY\">Speech recognition game<\/a>\r\n<h3>Pygame's Platform Game<\/h3>\r\n\r\n<a href=\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-5-sounds-and-mixer\/\"><img decoding=\"async\" src=\"https:\/\/i1.wp.com\/pythonprogramming.altervista.org\/wp-content\/uploads\/2020\/01\/climbercover.png?w=557&ssl=1\"\/ width=\"50%\"><\/a>\r\n<script>\r\nvar title = \"Platform Pygame\";\r\n\t\tvar links = [\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-animation-of-a-sprite-v-1-3\/\",\"Animation 1.3\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-v-2-better-coding-test-it-checking-fps-on-the-screen\/\",\"Animation 1.2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-how-to-display-the-frame-rate-fps-on-the-screen\/\",\"Display Frame rate\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-sprite-animation-update\/\",\"Animation 1.1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platformer-1\/\",\"Pygame Platform Game 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-platform-game-2\/\",\"Pygame Platform 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-3-recap-cheatsheet\/\",\"Pygame PLatform 3 - recap and some Cheat Sheet\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-4-background-and-stuffs\/\",\"Pygame Platform 4 - Background & organizing code\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platform-game-5-sounds-and-mixer\/\",\"Pygame Platform 5 - Sounds\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/platform-game-in-detail-part-1\/\",\"Game in detail part 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/map-maker-1-2\/\", \"Map maker 1.2\"]\r\n\t\t];\r\n\t\t<\/script>\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script>\r\n\r\n<h3>Other Pygame's posts<\/h3>\r\n\r\n<script>\r\nvar title = \"Pygame's Posts\"\r\nvar links = [\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-platformer-1\/\",\"Platform game 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/make-a-platform-game-with-pygame-dafluffypotato\/\",\"DaFluffyPotato Platform Tutorials\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-and-classic-arcade-games-pong\/\",\"Pong Game Full\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-draws-in-colors-app-to-draw-with-pygame\/\",\"PyGameGIF 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-draw-app-with-animation\/\",\"PyGameGIF 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pydraw-2-0-app-to-draw-gif\/\",\"PyDraw 2.0\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-drawing-2\/\",\"Draw with Pygame\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/animation-with-pygame\",\"Sprite animation 1\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/animation-on-pygame-2-free-characters-and-more-actions\/\",\"Sprite animation 2\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/starting-with-pygame\/\",\"Starting movements with Pygame\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-3-move-sprite\/\", \"Move a Sprite\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-4-fonts\/\",\"Text and Fonts\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-animate-a-sprite\/\", \"Animate a sprite\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pygame-and-mouse-events\/\",\"Mouse events\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/pgp-aka-pygamepresentation-project\/\",\"Pygame presentation\"],\r\n\t[\"https:\/\/pythonprogramming.altervista.org\/moving-the-player-in-pygame-with-key-get_pressed\/\",\"How to use key.get_pressed()\"]\r\n]\r\n<\/script>\r\n\r\n\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"Awesome widgets buttons for pygame\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/button-widget-in-pygame-updated\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":13360,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[191],"tags":[108,52,194],"class_list":["post-13358","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pygame","tag-buttons","tag-gui","tag-pygame"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":true,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=13358"}],"version-history":[{"count":4,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13358\/revisions"}],"predecessor-version":[{"id":13626,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/13358\/revisions\/13626"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/13360"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=13358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=13358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=13358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}