#turtle
Код из видео:
from turtle import *
# Значок черепашки
shape('turtle')
# Изменение окна
Screen().title("Черепашка") # Заголовок окна
Screen().setup(500, 500) # Разрешение окна
Screen().bgcolor("black") # Цвет окна
color('lime') # Цвет черепашки
speed(1) # Скорость черепашки
width(5) # Ширина линии
# Треугольник
# forward(50)
# left(120)
# forward(50)
# left(120)
# forward(50)
# Квадрат
# forward(50)
# left(90)
# forward(50)
# left(90)
# forward(50)
# left(90)
# forward(50)
# Круг
# radius = 100
# circle(radius)
# Спираль
# forw = 10
# while True:
# lef = 90
# forward(forw)
# left(lef)
# forw += 5
done()
Код из видео:
from turtle import *
# Значок черепашки
shape('turtle')
# Изменение окна
Screen().title("Черепашка") # Заголовок окна
Screen().setup(500, 500) # Разрешение окна
Screen().bgcolor("black") # Цвет окна
color('lime') # Цвет черепашки
speed(1) # Скорость черепашки
width(5) # Ширина линии
# Треугольник
# forward(50)
# left(120)
# forward(50)
# left(120)
# forward(50)
# Квадрат
# forward(50)
# left(90)
# forward(50)
# left(90)
# forward(50)
# left(90)
# forward(50)
# Круг
# radius = 100
# circle(radius)
# Спираль
# forw = 10
# while True:
# lef = 90
# forward(forw)
# left(lef)
# forw += 5
done()
#TkinterPack
Код из видео:
from tkinter import *
root = Tk()
root.title('Тестовое приложение')
root.geometry('1280x720')
root.resizable(width=False, height=False)
# root.config(bg = 'black')
root['bg'] = 'black'
l1 = Label(root, text='1', font='15', fg='white', bg='yellow', width=8, height=4).pack(side=LEFT)
l2 = Label(root, text='2', font='15', fg='white', bg='brown', width=8, height=4).pack(side=RIGHT)
l3 = Label(root, text='3', font='15', fg='white', bg='blue', width=8, height=4).pack(side=TOP)
l4 = Label(root, text='4', font='15', fg='white', bg='pink', width=8, height=4).pack(side=BOTTOM)
l6 = Label(root, text='6', font='15', fg='white', bg='yellow', width=8, height=4).pack(expand=1, anchor=SE)
root.mainloop()
Код из видео:
from tkinter import *
root = Tk()
root.title('Тестовое приложение')
root.geometry('1280x720')
root.resizable(width=False, height=False)
# root.config(bg = 'black')
root['bg'] = 'black'
l1 = Label(root, text='1', font='15', fg='white', bg='yellow', width=8, height=4).pack(side=LEFT)
l2 = Label(root, text='2', font='15', fg='white', bg='brown', width=8, height=4).pack(side=RIGHT)
l3 = Label(root, text='3', font='15', fg='white', bg='blue', width=8, height=4).pack(side=TOP)
l4 = Label(root, text='4', font='15', fg='white', bg='pink', width=8, height=4).pack(side=BOTTOM)
l6 = Label(root, text='6', font='15', fg='white', bg='yellow', width=8, height=4).pack(expand=1, anchor=SE)
root.mainloop()
🔥1
#Задачиpython
Код из видео:
n1 = int(input('Введите число: '))
n2 = 0
while n1 > 0:
digital = n1 % 10
print(digital)
n1 //= 10
print(n1)
n2 *= 10
n2 += digital
print(n2)
Код из видео:
n1 = int(input('Введите число: '))
n2 = 0
while n1 > 0:
digital = n1 % 10
print(digital)
n1 //= 10
print(n1)
n2 *= 10
n2 += digital
print(n2)
#TkinterPaint
Код из видео:
from tkinter import *
import PIL
from PIL import Image, ImageDraw
from tkinter import messagebox
from random import *
def save():
filename = f'image_{randint(0, 10000)}.png'
image1.save(filename)
messagebox.showinfo('Сохранение', 'Сохранено под названием %s' % filename)
def activate_paint(event):
x1, y1 = (event.x - 2), (event.y - 2)
x2, y2 = (event.x + 2), (event.y + 2)
cv.create_line(x1, y1, x2, y2, fill='black', width=5)
draw.line((x1, y1, x2, y2), fill='black', width=5)
root = Tk()
root.title("Рисовалка")
root.resizable(width=False, height=False)
cv = Canvas(root, width=1280, height=720, bg='white')
image1 = PIL.Image.new('RGB', (1280, 720), 'white')
draw = ImageDraw.Draw(image1)
cv.bind('<B1-Motion>', activate_paint)
cv.pack(expand=1, fill=BOTH)
btn_save = Button(text="save", command=save, bg='black', fg='white', font=('Comic Sans MS', 30))
btn_save.pack()
root.mainloop()
Код из видео:
from tkinter import *
import PIL
from PIL import Image, ImageDraw
from tkinter import messagebox
from random import *
def save():
filename = f'image_{randint(0, 10000)}.png'
image1.save(filename)
messagebox.showinfo('Сохранение', 'Сохранено под названием %s' % filename)
def activate_paint(event):
x1, y1 = (event.x - 2), (event.y - 2)
x2, y2 = (event.x + 2), (event.y + 2)
cv.create_line(x1, y1, x2, y2, fill='black', width=5)
draw.line((x1, y1, x2, y2), fill='black', width=5)
root = Tk()
root.title("Рисовалка")
root.resizable(width=False, height=False)
cv = Canvas(root, width=1280, height=720, bg='white')
image1 = PIL.Image.new('RGB', (1280, 720), 'white')
draw = ImageDraw.Draw(image1)
cv.bind('<B1-Motion>', activate_paint)
cv.pack(expand=1, fill=BOTH)
btn_save = Button(text="save", command=save, bg='black', fg='white', font=('Comic Sans MS', 30))
btn_save.pack()
root.mainloop()
#TkinterPlace
Код из видео:
from tkinter import *
root = Tk()
root.title('Тестовое приложение')
root.geometry('500x500')
root.resizable(width=False, height=False)
# root.config(bg = 'black')
root['bg'] = 'black'
label1 = Label(root, text='Привет!', fg='white', bg='brown', padx=20, pady=20)
label1.place(relx=0.5, rely=0.5, anchor=CENTER, relwidth=0.5, relheight=0.5)
root.mainloop()
Код из видео:
from tkinter import *
root = Tk()
root.title('Тестовое приложение')
root.geometry('500x500')
root.resizable(width=False, height=False)
# root.config(bg = 'black')
root['bg'] = 'black'
label1 = Label(root, text='Привет!', fg='white', bg='brown', padx=20, pady=20)
label1.place(relx=0.5, rely=0.5, anchor=CENTER, relwidth=0.5, relheight=0.5)
root.mainloop()
#TkinterСекундомер
Код из видео:
from tkinter import *
from datetime import datetime
temp = 0
after_id = ''
def tick():
global temp, after_id
after_id = root.after(1000, tick)
f_temp = datetime.fromtimestamp(temp).strftime("%M:%S")
label1.configure(text=str(f_temp))
temp += 1
def start_tick():
btnStart.pack_forget()
btnStop.pack()
tick()
def stop_tick():
btnStop.pack_forget()
btnContinue.pack()
btnReset.pack()
root.after_cancel(after_id)
def continue_tick():
btnContinue.pack_forget()
btnReset.pack_forget()
btnStop.pack()
tick()
def reset_tick():
global temp
temp = 0
label1.configure(text='00:00')
btnContinue.pack_forget()
btnReset.pack_forget()
btnStart.pack()
root = Tk()
root.title('Секундомер')
root.resizable(width=False, height=False)
root.geometry('300x200')
label1 = Label(root, width=10, font=('Comic Sans MS', 30), text='00:00')
label1.pack()
btnStart = Button(root, text='Старт', font=('Comic Sans MS', 20), width=15, command=start_tick)
btnStop = Button(root, text='Стоп', font=('Comic Sans MS', 20), width=15, command=stop_tick)
btnContinue = Button(root, text='Продолжить', font=('Comic Sans MS', 20), width=15, command=continue_tick)
btnReset = Button(root, text='Сброс', font=('Comic Sans MS', 20), width=15, command=reset_tick)
btnStart.pack()
root.mainloop()
Код из видео:
from tkinter import *
from datetime import datetime
temp = 0
after_id = ''
def tick():
global temp, after_id
after_id = root.after(1000, tick)
f_temp = datetime.fromtimestamp(temp).strftime("%M:%S")
label1.configure(text=str(f_temp))
temp += 1
def start_tick():
btnStart.pack_forget()
btnStop.pack()
tick()
def stop_tick():
btnStop.pack_forget()
btnContinue.pack()
btnReset.pack()
root.after_cancel(after_id)
def continue_tick():
btnContinue.pack_forget()
btnReset.pack_forget()
btnStop.pack()
tick()
def reset_tick():
global temp
temp = 0
label1.configure(text='00:00')
btnContinue.pack_forget()
btnReset.pack_forget()
btnStart.pack()
root = Tk()
root.title('Секундомер')
root.resizable(width=False, height=False)
root.geometry('300x200')
label1 = Label(root, width=10, font=('Comic Sans MS', 30), text='00:00')
label1.pack()
btnStart = Button(root, text='Старт', font=('Comic Sans MS', 20), width=15, command=start_tick)
btnStop = Button(root, text='Стоп', font=('Comic Sans MS', 20), width=15, command=stop_tick)
btnContinue = Button(root, text='Продолжить', font=('Comic Sans MS', 20), width=15, command=continue_tick)
btnReset = Button(root, text='Сброс', font=('Comic Sans MS', 20), width=15, command=reset_tick)
btnStart.pack()
root.mainloop()
👍2
#TkinterКликер
Код из видео:
from tkinter import *
from tkinter import messagebox
from random import *
clicks = 0
def randomize():
global clicks
btnClick.place(x=randint(70, 1000), y=randint(70, 650))
clicks += 1
labelClick['text'] = str(clicks)
labelClick.pack()
root = Tk()
root.title('Кликер')
root.geometry('1280x720')
root.resizable(width=False, height=False)
root['bg'] = 'black'
labelClick = Label(root, text='0', font=('Comic Sans MS', 30, 'bold'), bg='black', fg='white')
labelClick.pack()
btnClick = Button(root,
text='Click',
bg='lime',
fg='black',
padx='20',
pady='8',
font=('Comic Sans MS', 13, 'bold'),
command=randomize
)
btnClick.place(x=randint(70, 1000), y=randint(70, 650))
root.mainloop()
Код из видео:
from tkinter import *
from tkinter import messagebox
from random import *
clicks = 0
def randomize():
global clicks
btnClick.place(x=randint(70, 1000), y=randint(70, 650))
clicks += 1
labelClick['text'] = str(clicks)
labelClick.pack()
root = Tk()
root.title('Кликер')
root.geometry('1280x720')
root.resizable(width=False, height=False)
root['bg'] = 'black'
labelClick = Label(root, text='0', font=('Comic Sans MS', 30, 'bold'), bg='black', fg='white')
labelClick.pack()
btnClick = Button(root,
text='Click',
bg='lime',
fg='black',
padx='20',
pady='8',
font=('Comic Sans MS', 13, 'bold'),
command=randomize
)
btnClick.place(x=randint(70, 1000), y=randint(70, 650))
root.mainloop()
#TkinterFrame
Код из видео:
frame_top = Frame(root) # root можно не указывать
frame_top.pack(side=LEFT)
label_1 = Label(frame_top, width=7, height=4, bg='yellow', text="1")
label_1.pack(side=LEFT)
label_2 = Label(frame_top, width=7, height=4, bg='orange', text="2")
label_2.pack(side=LEFT)
frame_bottom = Frame(root)
frame_bottom.pack(side=LEFT)
label_3 = Label(frame_bottom, width=7, height=4, bg='lightgreen', text="3")
label_3.pack(side=LEFT)
label_4 = Label(frame_bottom, width=7, height=4, bg='lightblue', text="4")
label_4.pack(side=LEFT)
Кроме Frame существует похожий класс LabelFrame – фрейм с подписью.
В отличие от простого фрейма у него есть свойство text:
frame_top = LabelFrame(text="Верх")
frame_top.pack()
label_1 = Label(frame_top, width=7, height=4, bg='yellow', text="1")
label_1.pack(side=LEFT)
label_2 = Label(frame_top, width=7, height=4, bg='orange', text="2")
label_2.pack(side=LEFT)
frame_bottom = LabelFrame(text="Низ")
frame_bottom.pack()
label_3 = Label(frame_bottom, width=7, height=4, bg='lightgreen', text="3")
label_3.pack(side=LEFT)
label_4 = Label(frame_bottom, width=7, height=4, bg='lightblue', text="4")
label_4.pack(side=LEFT)
Горизонтальное расположение
frame_top.pack(side=LEFT)
frame_bottom.pack(side=LEFT)
Код из видео:
frame_top = Frame(root) # root можно не указывать
frame_top.pack(side=LEFT)
label_1 = Label(frame_top, width=7, height=4, bg='yellow', text="1")
label_1.pack(side=LEFT)
label_2 = Label(frame_top, width=7, height=4, bg='orange', text="2")
label_2.pack(side=LEFT)
frame_bottom = Frame(root)
frame_bottom.pack(side=LEFT)
label_3 = Label(frame_bottom, width=7, height=4, bg='lightgreen', text="3")
label_3.pack(side=LEFT)
label_4 = Label(frame_bottom, width=7, height=4, bg='lightblue', text="4")
label_4.pack(side=LEFT)
Кроме Frame существует похожий класс LabelFrame – фрейм с подписью.
В отличие от простого фрейма у него есть свойство text:
frame_top = LabelFrame(text="Верх")
frame_top.pack()
label_1 = Label(frame_top, width=7, height=4, bg='yellow', text="1")
label_1.pack(side=LEFT)
label_2 = Label(frame_top, width=7, height=4, bg='orange', text="2")
label_2.pack(side=LEFT)
frame_bottom = LabelFrame(text="Низ")
frame_bottom.pack()
label_3 = Label(frame_bottom, width=7, height=4, bg='lightgreen', text="3")
label_3.pack(side=LEFT)
label_4 = Label(frame_bottom, width=7, height=4, bg='lightblue', text="4")
label_4.pack(side=LEFT)
Горизонтальное расположение
frame_top.pack(side=LEFT)
frame_bottom.pack(side=LEFT)
#Задачиpython
Код из видео:
print('A(x1; y1):')
x1 = float(input('x1 = '))
y1 = float(input('y1 = '))
print('B(x1; y1):')
x2 = float(input('x2 = '))
y2 = float(input('y2 = '))
print('Уравнение:')
k = (y1 - y2) / (x1 - x2)
b = y2 - k * x2
print('\ty = %.2f*x + %.2f' % (k, b))
Код из видео:
print('A(x1; y1):')
x1 = float(input('x1 = '))
y1 = float(input('y1 = '))
print('B(x1; y1):')
x2 = float(input('x2 = '))
y2 = float(input('y2 = '))
print('Уравнение:')
k = (y1 - y2) / (x1 - x2)
b = y2 - k * x2
print('\ty = %.2f*x + %.2f' % (k, b))