import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((250, 250))
self.SetTitle("frame")
sizer_1 = wx.WrapSizer(wx.VERTICAL)
fields = [
("Ширина (м)", "a"),
("Длина (м)", "b"),
("Высота (м)", "h"),
("Окно ширина (м)", "o1"),
("Окно высота (м)", "o2"),
("Дверь ширина (м)", "d1"),
("Дверь высота (м)", "d2"),
]
# Create grid sizers and controls dynamically
for label_text, attr in fields:
grid_sizer = wx.GridSizer(1, 2, 0, 0)
sizer_1.Add(grid_sizer, 1, wx.EXPAND, 0)
label = wx.StaticText(self, wx.ID_ANY, label_text)
grid_sizer.Add(label, 0, wx.ALL, 1)
text_ctrl = wx.TextCtrl(self, wx.ID_ANY, "")
setattr(self, attr, text_ctrl) # Store the text control in the instance
grid_sizer.Add(text_ctrl, 0, 0, 0)
# Create a horizontal sizer for the result and button
h_sizer = wx.BoxSizer(wx.HORIZONTAL)
# Result text control
self.itogo = wx.TextCtrl(self, wx.ID_ANY, "")
self.itogo.SetBackgroundColour((171, 171, 171))
h_sizer.Add(self.itogo, 1, wx.EXPAND | wx.ALL, 5)
# Calculate button
self.button_1 = wx.Button(self, wx.ID_ANY, "Посчитать", size=(110, 21))
h_sizer.Add(self.button_1, 0, wx.ALL, 5)
self.button_1.Bind(wx.EVT_BUTTON, self.onclick)
# Add the horizontal sizer to the main sizer
sizer_1.Add(h_sizer, 0, wx.EXPAND, 0)
self.SetSizer(sizer_1)
self.Layout()
def onclick(self, event):
a = float(self.a.GetValue())
b = float(self.b.GetValue())
h = float(self.h.GetValue())
o1 = float(self.o1.GetValue())
o2 = float(self.o2.GetValue())
d1 = float(self.d1.GetValue())
d2 = float(self.d2.GetValue())
result = round(a * 2 * h + b * 2 * h - o1 * o2 - d1 * d2, 2)
self.itogo.SetValue(str(result))
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
r
перед ф-строкой во избежание нескольких invalid escape sequence:command = rf'C:\PsTools\psexec.exe -i 1 -s \\192.168.11.18 -u user -p password calc.exe'
import subprocess
def f():
command = rf'C:\Portable\Sysinternal\PsExec.exe -i 1 -s \\192.168.0.3 -u user -p password calc.exe'
return subprocess.call(command, stdout=subprocess.DEVNULL)
interactive=True
, надо указать номер сессии (можно узнать через cmd -> query user
), например: interactive_session=1
. Это аналог -i 1
в psexec.c.run_executable (executable: "cmd.exe", arguments=r"/c start calc.exe", interactive=True, interactive_session=1)
num_1 = None
num_2 = None
effect = None
while True:
if num_1 is None:
input_value = input("Введите первое число: ")
if input_value.isdigit():
num_1 = int(input_value)
else:
print('Вы ввели не число!')
continue
if num_2 is None:
input_value = input("Введите второе число: ")
if input_value.isdigit():
num_2 = int(input_value)
else:
print('Вы ввели не число!')
continue
if effect is None:
input_value = input(
"Напишите что вы хотите сделать (отнять, прибавить, умножить, разделить, возвести в степень, целое деление, остаток от деления): ")
if input_value in ("+", "-", "*", "/", "**", "//", "%"):
effect = input_value
break
else:
print('Нету такого действия!')
continue
# Выполнение операции
if effect == "+":
print(num_1 + num_2)
elif effect == "-":
print(num_1 - num_2)
elif effect == "*":
print(num_1 * num_2)
elif effect == "/":
print(num_1 / num_2)
elif effect == "**":
print(num_1 ** num_2)
elif effect == "//":
print(num_1 // num_2)
elif effect == "%":
print(num_1 % num_2)
config.getint("User", "id")
возвращает тип int, а у данного типа нет метода (атрибута) 'send'.user_id.send("Ваша заявка была одобрена")
вызовет ошибку выше.user = await bot.fetch_user(user_id: int)
await user.send(message)
import torch
torch.cuda.is_available()
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(device)
model = MyModel(args)
model.to(device)
l = []
for i in range(3):
l.append(lambda: i)
print([f() for f in l])
>>> [2, 2, 2]
l = []
for i in range(3):
l.append(lambda i = i : i)
print([f() for f in l])
>>> [0, 1, 2]
while True:
try:
x = pa.locateCenterOnScreen(r"C:\Python Scripts\library\proga.png", confidence=0.5)
print(x)
except Exception as e:
print(e)
len_pass_numbers.lower()
(и прочие) возвращает вам строку 'да', а вы сравниваете с 'Да'. chars
- пустой.from string import digits, ascii_lowercase, ascii_uppercase, punctuation
import requests
url = 'https://texttospeech.ru/api/v1/login'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0',
'Content-Type': 'text/plain;charset=UTF-8',
}
data = {"email": "sample@email.com", "pass": "password", "captcha": ""}
session = requests.Session()
response = session.post(url, json=data)
print(response.text)
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0',
'Content-Type': 'text/plain;charset=UTF-8',
}
def get_token() -> str:
url = 'https://texttospeech.ru/api/v1/login'
data = {"email": "sample@email.com", "pass": "password", "captcha": ""}
with requests.Session() as session:
response = session.post(url, headers=headers, json=data)
token = response.json().get('data').get('token')
return token
headers['token'] = get_token()
def synthesize(text: str) -> None:
url = 'https://texttospeech.ru/api/v1/synthesize'
data = {"rate": "0", "pitch": "0", "volume": "0", "hertz": "0", "shift": "0", "echo": "0",
"text": f'{text}',
"code": "ru-RU009",
"format": "mp3"}
with requests.Session() as session:
response = session.post(url, headers=headers, json=data)
if response.status_code == 200:
print(response.json().get('message'))
filelink = response.json().get('data').get('filelink')
with open(f'{text[0:10]}.mp3', 'wb') as file:
response = session.get(f'https://texttospeech.ru/{filelink}', headers=headers)
file.write(response.content)
else:
print(response.text)
synthesize('Привет мир')
on_component
- это не атрибут бота, а внутреннее событие.# Обработчик нажатия на кнопку присоединения к игре
@bot.event
async def on_component(interaction):
global players
if interaction.author not in players:
players[interaction.author] = None
await interaction.response.send_message(content=f"{interaction.author.mention} присоединился к игре!",
ephemeral=True)
else:
await interaction.response.send_message(content="Вы уже присоединились к игре!", ephemeral=True)
intents = disnake.Intents.all()