June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,55 +1,44 @@
import pygame, sys
from pygame.locals import *
pygame.init()
#!/usr/bin/env python3
import sys
YSIZE = 40
XSIZE = 150
from PyQt5.QtCore import QBasicTimer, Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication, QLabel
TEXT = "Hello World! "
FONTSIZE = 32
LEFT = False
RIGHT = True
class Marquee(QLabel):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.right_to_left_direction = True
self.initUI()
self.timer = QBasicTimer()
self.timer.start(80, self)
DIR = RIGHT
def initUI(self):
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setText("Hello World! ")
self.setFont(QFont(None, 50, QFont.Bold))
# make more irritating for the authenticity with <marquee> element
self.setStyleSheet("QLabel {color: cyan; }")
TIMETICK = 180
TICK = USEREVENT + 2
def timerEvent(self, event):
i = 1 if self.right_to_left_direction else -1
self.setText(self.text()[i:] + self.text()[:i]) # rotate
TEXTBOX = pygame.Rect(10,10,XSIZE,YSIZE)
def mouseReleaseEvent(self, event): # change direction on mouse release
self.right_to_left_direction = not self.right_to_left_direction
pygame.time.set_timer(TICK, TIMETICK)
def keyPressEvent(self, event): # exit on Esc
if event.key() == Qt.Key_Escape:
self.close()
window = pygame.display.set_mode((XSIZE, YSIZE))
pygame.display.set_caption("Animation")
font = pygame.font.SysFont(None, FONTSIZE)
screen = pygame.display.get_surface()
def rotate():
index = DIR and -1 or 1
global TEXT
TEXT = TEXT[index:]+TEXT[:index]
def click(position):
if TEXTBOX.collidepoint(position):
global DIR
DIR = not DIR
def draw():
surface = font.render(TEXT, True, (255,255,255), (0,0,0))
global TEXTBOX
TEXTBOX = screen.blit(surface, TEXTBOX)
def input(event):
if event.type == QUIT:
sys.exit(0)
elif event.type == MOUSEBUTTONDOWN:
click(event.pos)
elif event.type == TICK:
draw()
rotate()
while True:
input(pygame.event.wait())
pygame.display.flip()
app = QApplication(sys.argv)
w = Marquee()
# center widget on the screen
w.adjustSize() # update w.rect() now
w.move(QApplication.instance().desktop().screen().rect().center()
- w.rect().center())
w.show()
sys.exit(app.exec())

View file

@ -1,23 +1,55 @@
import Tkinter as tki
import pygame, sys
from pygame.locals import *
pygame.init()
def scroll_text(s, how_many):
return s[how_many:] + s[:how_many]
YSIZE = 40
XSIZE = 150
direction = 1
tk = tki.Tk()
var = tki.Variable(tk)
TEXT = "Hello World! "
FONTSIZE = 32
def mouse_handler(point):
global direction
direction *= -1
LEFT = False
RIGHT = True
def timer_handler():
var.set(scroll_text(var.get(),direction))
tk.after(125, timer_handler)
DIR = RIGHT
var.set('Hello, World! ')
tki.Label(tk, textvariable=var).pack()
tk.bind("<Button-1>", mouse_handler)
tk.after(125, timer_handler)
tk.title('Python Animation')
tki.mainloop()
TIMETICK = 180
TICK = USEREVENT + 2
TEXTBOX = pygame.Rect(10,10,XSIZE,YSIZE)
pygame.time.set_timer(TICK, TIMETICK)
window = pygame.display.set_mode((XSIZE, YSIZE))
pygame.display.set_caption("Animation")
font = pygame.font.SysFont(None, FONTSIZE)
screen = pygame.display.get_surface()
def rotate():
index = DIR and -1 or 1
global TEXT
TEXT = TEXT[index:]+TEXT[:index]
def click(position):
if TEXTBOX.collidepoint(position):
global DIR
DIR = not DIR
def draw():
surface = font.render(TEXT, True, (255,255,255), (0,0,0))
global TEXTBOX
TEXTBOX = screen.blit(surface, TEXTBOX)
def input(event):
if event.type == QUIT:
sys.exit(0)
elif event.type == MOUSEBUTTONDOWN:
click(event.pos)
elif event.type == TICK:
draw()
rotate()
while True:
input(pygame.event.wait())
pygame.display.flip()

View file

@ -0,0 +1,23 @@
import Tkinter as tki
def scroll_text(s, how_many):
return s[how_many:] + s[:how_many]
direction = 1
tk = tki.Tk()
var = tki.Variable(tk)
def mouse_handler(point):
global direction
direction *= -1
def timer_handler():
var.set(scroll_text(var.get(),direction))
tk.after(125, timer_handler)
var.set('Hello, World! ')
tki.Label(tk, textvariable=var).pack()
tk.bind("<Button-1>", mouse_handler)
tk.after(125, timer_handler)
tk.title('Python Animation')
tki.mainloop()