Можно ли запустить Firefox или Chrome в окне pygame с Python? - PullRequest
1 голос
/ 27 мая 2020

У меня есть программа Pygame, и я нашел на inte rnet веб-сайт с живым объектом html, который я хотел найти в своем окне pygame. Я пробовал много модулей, но не нашел того, что хотел.

Возможно ли иметь все окно / онглет Firefox или Chrome, или только (div) html объект.

Вот мой код pygame:

import pygame
import pyperclip
import autoit
import math
import time
import tkinter as tk
from tkinter import filedialog
import os
import ftplib
from shutil import copyfile
from datetime import datetime
import pytz
from random import seed
from random import randint
import time
file1 = open('nvpn.txt', 'r')
Lines = file1.readlines()
# Start pygame
pygame.init()
clock = pygame.time.Clock()
# set the pygame window name
pygame.display.set_caption('Agents of shield')
# define the RGB value for white,
#  green, blue colour .
white = (255, 255, 255)
green = (0, 255, 0)
blue = (0, 0, 128)
class CustText:
    def __init__(self,content, fontSize, color1, color2, posX, posY):
        self.text = pygame.font.Font('freesansbold.ttf', fontSize).render(content, True, color1, color2)
        x = self.text.get_rect()[0]/2
        y = self.text.get_rect()[1]/2
        self.textRect = (int(x) + posX, int(y) + posY)


def main():
    loop = True
    fenetre = pygame.display.set_mode((640, 480))
    # Desclarations
    a1 = Lines[randint(0, 2)]
    Text2 = CustText(a1, 18, (0, 0, 0), (255, 255, 255), 10, 100)
    print(a1)
    while loop:
        fenetre.fill(white)
        a = datetime.now(pytz.timezone('America/New_York')).strftime("%H:%M:%S")

        heures = a[0] + a[1]
        minutes = a[3] + a[4]
        seconde = a[6] + a[7]

        difSec = 60 - int(seconde)
        difMin = 59 - int(minutes)
        if datetime.now().day == 26:
            difHeures = 43 - int(heures)
        else:
            difHeures = 43 - int(heures)

        a2 = str(difHeures) + "H " + str(difMin) + "M " + str(difSec) + "S "
        timeInEast2 = a2
        timeInEast = str(a)

        Text1 = CustText(timeInEast, 30, (0, 0, 0), (255, 255, 255), 10, 10)
        Text3 = CustText(timeInEast2, 30, (0, 0, 0), (255, 255, 255), 10, 50)

        fenetre.blit(Text1.text, Text1.textRect)
        fenetre.blit(Text2.text, Text2.textRect)
        fenetre.blit(Text3.text, Text3.textRect)

        # Si quitter alors quitter
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                while True:
                    quit()
        if pygame.mouse.get_pressed()[2]:
            pyperclip.copy(a1.split(":")[0])
        if pygame.mouse.get_pressed()[0]:
            pyperclip.copy(a1.split(":")[1])

        # Actualisation de l'affichage
        pygame.display.flip()
        clock.tick(30)
if __name__ == '__main__':
    main()

1 Ответ

0 голосов
/ 27 мая 2020

Вероятно, вы могли бы использовать модуль beautifulsoup, чтобы очистить веб-сайт и вытащить изображение, а затем отобразить его в своей игре. Однако могут возникнуть проблемы с авторским правом при использовании изображения с такого веб-сайта.

Ответ здесь показывает использование beautifulsoup для извлечения изображений с веб-сайта и сохранения их в виде файлов в каталоге. Вам не нужно сохранять их на диск, хотя вы можете просто сохранить их в своей игре и использовать по мере необходимости. Я не тестировал код в ответе, поэтому не могу подтвердить, что он работает. Я нашел его, выполнив поиск в Google «получить изображение с веб-сайта с помощью beautifulsoup».

...