import requests
from bs4 import BeautifulSoup
def get_html(site):
r = requests.get(site)
return r.text
def get_page_data(html): #sources
soup = BeautifulSoup(html, 'lxml') #(format_in, parser)
line = soup.find('table', id='theProxyList').find_all('tr') #resolve table
for tr in line:
td = tr.find_all('td')
if td == []:
continue
ip = td[1].text
port = td[2].text
country = td[3].text
anonym = td[4].text
types = td[5].text
time = td[6].text
data = {'ip': ip,
'Port': port,
'Country': country,
'Anonymize': anonym,
'Type': types,
'Time': time}
print(data)
def main():
url = 'http://foxtools.ru/Proxy'
get_page_data(get_html(url))
if __name__ == '__main__':
main()
import io
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import requests
def log_uncaught_exceptions(ex_cls, ex, tb):
text = '{}: {}:\n\n'.format(ex_cls.__name__, ex)
import traceback
text += ''.join(traceback.format_tb(tb))
QMessageBox.critical(None, 'Ошибка!', text)
quit()
sys.excepthook = log_uncaught_exceptions
class SenderMessage(QObject):
image_bytes = pyqtSignal(bytes)
def __init__(self):
super().__init__()
@pyqtSlot()
def run(self):
image_bytes = requests.get('https://dadaviz.ru/wp-content/uploads/2018/02/1-12.jpg', stream=True).content
self.image_bytes.emit(image_bytes)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("Показать изображение")
self.setGeometry(400, 200, 626, 626)
self.label_image = QLabel(self)
self.label_image.setGeometry(0, 0, 626, 626)
self.pixmap = QPixmap()
self.thread = QThread()
self.sender_message = SenderMessage()
self.sender_message.moveToThread(self.thread)
self.sender_message.image_bytes.connect(self.signalHandlerImageBytes)
self.thread.started.connect(self.sender_message.run)
self.thread.start()
def signalHandlerImageBytes(self, image_bytes):
self.pixmap.loadFromData(image_bytes)
self.label_image.setPixmap(self.pixmap)
def main():
app = QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
from tkinter import Tk, Button, Label, LabelFrame, mainloop
from functools import partial
SIGNAL = int
class App(Tk):
normal_engine_speed = 1500
def __init__(self):
super().__init__()
self.interface()
def interface(self):
self.title("Управление станком")
self["bg"] = "gray22"
self.geometry("300x150+500+300")
self.resizable(False, False)
title_label = Label(self, text="Обороты двигателя")
title_label.config(font="Times 18 bold", fg="green")
title_label.place(x=40)
button_reduce_speed = Button(self, text="-10")
button_reduce_speed.config(font="Times 13 bold", fg="blue")
button_reduce_speed.bind('<Button-1>', partial(self.button_click_handler, 0))
button_reduce_speed.place(x=0, y=0)
button_add_speed = Button(self, text="+10")
button_add_speed.config(font="Times 13 bold", fg="blue")
button_add_speed.bind('<Button-1>', partial(self.button_click_handler, 1))
button_add_speed.place(x=261, y=0)
self.show_engine_speed = Label(self, text=self.normal_engine_speed)
self.show_engine_speed.config(font="Times 30 bold", bg="black", fg="green")
self.show_engine_speed.config(width=13, height=2)
self.show_engine_speed.place(y=40)
def button_click_handler(self, SIGNAL, event):
if SIGNAL == 0:
self.normal_engine_speed -= 10
elif SIGNAL == 1:
self.normal_engine_speed += 10
self.show_engine_speed["text"] = self.normal_engine_speed
if __name__ == "__main__":
app = App()
app.mainloop()
import sys
import numpy
from PIL import Image
from PIL.ImageQt import ImageQt
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QMessageBox
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtCore import Qt
def log_uncaught_exceptions(ex_cls, ex, tb):
text = '{}: {}:\n\n'.format(ex_cls.__name__, ex)
import traceback
text += ''.join(traceback.format_tb(tb))
QMessageBox.critical(None, 'Ошибка!', text)
quit()
sys.excepthook = log_uncaught_exceptions
class ShowImage(QMainWindow):
def __init__(self):
super().__init__()
self.interface()
def interface(self):
self.setWindowTitle("Пример рисования изображения")
self.setGeometry(400, 200, 600, 400)
pixel = numpy.zeros((10, 10, 3)).astype(int)
pixel[0][0][2] = 255
print(pixel)
image = Image.fromarray(pixel, 'RGB')
self.image_qt = ImageQt(image)
pixmap = QPixmap(QImage(self.image_qt))
label = QLabel(self)
label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
label.setStyleSheet("background-color: white")
label.setGeometry(0, 0, 100, 100)
label.setPixmap(pixmap)
if __name__ == "__main__":
app = QApplication(sys.argv)
my_application = ShowImage()
my_application.show()
sys.exit(app.exec_())
from tkinter import *
import pyautogui as pag
class AutoTap(Tk):
def __init__(self):
super().__init__()
self.button = Button(self, text="кнопка")
self.button.config(command=self.signal_handler, width=15)
self.button.pack()
self.label = Label(self)
self.label.pack()
self.auto_tap()
def signal_handler(self):
self.label["text"] = "нажата кнопка{0}".format(str(self.button.winfo_rootx()))
def auto_tap(self):
pag.click(self.button.winfo_rootx()+5, self.button.winfo_rooty()+5)
self.after(5000, self.auto_tap)
app = AutoTap()
app.mainloop()
from random import randint
from tkinter import Tk, Label, mainloop
from time import sleep
class App(Tk):
def __init__(self):
super().__init__()
self.label = Label(self)
self.label.pack()
self.run()
def run(self):
self.label["text"] = str(randint(1, 10000))
self.after(1000, self.run)
app = App()
app.mainloop()
from time import sleep
import webbrowser
def dialog():
print("Привет!")
while True: # Бесконечный цикл пока не будет вызвана инструкция break
user = input("--> ")
if user == "привет":
print("Как дела?")
elif user == "отлично":
print("Молодец, так держать!")
break
elif user == "хорошо":
print("Я за тебя рад!")
break
elif user == "не очень":
print("А что случилось?")
user = input("--> ")
if user == "не могу выстроить логическую цепочку":
print("Одну минуточку...")
sleep(3)
webbrowser.open("https://pythonworld.ru/osnovy/instrukciya-if-elif-else-proverka-istinnosti-trexmestnoe-vyrazhenie-ifelse.html")
else:
break
input("Программа завершила свою работу для выхода нажмите Enter")
dialog()
import os
import tkinter as tk
from tkinter import *
#for name in os.listdir("C://"):
# print (name)
class Main(tk.Frame):
def __init__(self, root):
super().__init__(root)
self.toolbar()
self.Text()
def toolbar(self): # Добавляю в тулбар кнопки
toolbar = tk.Frame(bg='#d7d8e0', bd=4) # Создаём тулбар
toolbar.pack(side=tk.TOP, fill=tk.X)
btn_new = tk.Button(toolbar, text='Создать файл', bd = 4)
btn_new.pack(side=tk.LEFT)
btn_save = tk.Button(toolbar, text='Сохранить файл', bd = 4, command=self.saveTextField)# Вот здесь вы вызываете функцию но не передаёте параметры saveTextField(self, textField << Вот) да и по моему пр таком вызове и нельзя передать параметры
btn_save.pack(side=tk.LEFT)
def saveTextField(self):
with open("example.txt", "w") as file:
file.write(self.textField.get(1.0, END))
def Text(self):
self.textField = Text(width=200, height=100, fg='black', wrap=WORD) # что сделать object доступным во всём классе используйте self я вот это self.textField использую в это функции saveTextField
self.textField.pack()
if __name__ == "__main__": # Если окно запущенно, то создает наше главное окно
root = tk.Tk()
app = Main(root)
app.pack()
root.title("Text 0.01v")
root.geometry("800x600+450+100")
root.resizable(True, True)
root.mainloop()