self.fire = False
def check_keydown_events(event, ship, settings, screen, bullets):
if event.key == pygame.K_LEFT:
# left arrow keydown events
ship.move_left = True # moves ship left when key's keeping pressed
if event.key == pygame.K_RIGHT:
# right arrow keydown events
ship.move_right = True # moves ship right when key's keeping pressed
if event.key == pygame.K_DOWN:
# down arrow keydown events
ship.move_down = True # moves ship down when key's keeping pressed
if event.key == pygame.K_UP:
# up arrow keydown events
ship.move_up = True # moves ship up when key's keeping pressed
if event.key == pygame.K_SPACE:
ship.fire = True
def check_events(ship, settings, screen, bullets):
"""main event checker function"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
# working on keydown events
check_keydown_events(event, ship, settings, screen, bullets)
# function that checks keydown event type and works according event type
elif event.type == pygame.KEYUP:
check_keyup_events(event, ship)
# function that checks keyup event type and works according event type
print(len(bullets)) # to check amount of bullets on screen
if ship.fire and len(bullets) < settings.bullets_allowed:
# continues firing until amount of bullets reaches limit
new_bullet = Bullet(settings, ship, screen) # creating new bullet
bullets.add(new_bullet) # adding created bullet to Group
combined_csv = pd.concat([pd.read_csv(f, sep=";") for f in all_filenames ])
def something():
if check != 0:
# какие-то вычисления
root.after(1000, something)
# для запуска самого цикла из основного кода программы
root.after(0, something)
insert_query = """ INSERT INTO postgreetest_db (t1, t2, t3, t4, t5, t6, t7) VALUES (%s, %s, %s, %s, %s, %s, %s)"""
cursor.execute(insert_query, resultat)
photo = max(msg.photo, key=lambda x: x.height)
file_id = photo.file_id
ctrl = (event.state & 4) != 0 # признак нажатия Ctrl
self.bt = Button(root, text="gg", command=self.a)
# и потом для удаления можно будет сделать
self.bt.destroy()
class But(Button):
def __init__(self,root,coords):
super().__init__(root, text="gg", command=self.a)
self.grid(row=1, column=coords)
def a(self):
print("bt")
self.destroy()
cur.execute("SELECT * FROM users WHERE id = ?", (id, ))
all = cur.fetchone()
cur.execute("SELECT COUNT(*) FROM users WHERE id = ?", (id, ))
cnt = cur.fetchone()[0]
в cnt будет кол-во записей с этим пользователем, т.е. 1 если есть, 0 если нет. <sqlite3.Cursor ...
а не просто пустую строку....
user_info = sql.execute(f"SELECT tiktok, cash from users WHERE login = '{message.from_user.id}'").fetchone()
if user_info:
tik, balance = user_info
bot.send_message(message.chat.id, f"ваш тикток: {tik}")
bot.send_message(message.chat.id, f" Ваш баланс: {balance} RUB ")
if call.data == 'r':
status = ['creator', 'administrator', 'member']
chats = ["@footballdaily24", "@social_net_itnews"]
for chat_id in chats:
chri == bot.get_chat_member(chat_id=chat_id, user_id=call.from_user.id).status
if chri not in status:
bot.send_message(call.message.chat.id, f"Кажется вы не подписались на {chat_id} ")
def get_access_status(user_id):
cursor.execute("SELECT 1 FROM Dostyp WHERE Iduser = %s", (user_id, ))
return bool(cursor.fetchone())
# сам проверка в функции
@bot.message_handler(commands=['start'])
def welcome(message):
if get_access_status(message.from_user.id):
# доступ есть, продолжаем
data = [
['13','2да','3нет','4впредкушение','53','654','7русский'],
['13','2да','3нет','4влюбленность','50','62','7русский']
]
out = [','.join(row)+'\n' for row in data]
with open('document.csv', 'a') as fd:
fd.writelines(out)
import csv
data = [
['13','2да','3нет','4впредкушение','53','654','7русский'],
['13','2да','3нет','4влюбленность','50','62','7русский']
]
with open('document2.csv', 'w', newline='') as fd:
writer = csv.writer(fd)
writer.writerows(data)
print(sorted(data, key=lambda x: datetime.datetime.strptime(x['history_date'], '%d.%m.%Y, %H:%M'), reverse=True))
import tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root)
canvas.pack(fill="both", expand=True)
# можно хранить в атрибутах canvas
canvas.max_oval_count = 10
canvas.ovals = []
class Oval():
...
def oval(event):
# создаем фигуры в списке
if canvas.max_oval_count > 0:
canvas.ovals.append(Oval(event, canvas))
canvas.max_oval_count -= 1
def move_ovals(event):
for oval in canvas.ovals:
oval.move_oval(event)
canvas.bind('<Button-3>', oval)
canvas.bind('<Button-1>', move_ovals)
root.mainloop()