Python

Python – OpenCV VSCode problems fix

Table of Contents

Intro

If your VSCode gives you Problems while import cv2 and can’t use autoComplete with it, here is you fix.

Instructions

Solution

    1. On VScode: CTRL + Shift + P
    2. Choose “Preferences: Open Settings (JSON)”
    3. Add this line into JSON file:
      "python.linting.pylintArgs": ["--generate-members"]
    4. Done, it works for me 👍

settings.json

				
					    "python.linting.pylintArgs": [
        "--generate-members"
    ]
				
			

Example Code

				
					import cv2
import numpy

img = numpy.zeros([320, 320], numpy.uint8)
cv2.imshow("test", img)
cv2.waitKey()
cv2.destroyAllWindows()
				
			

Python – TelegramAPI

Table of Contents

Intro

Short Intro in to Telegram API with pyTelegramBotAP

Instructions

Code

				
					import telebot

TOKEN = 'YOUR_BOT_TOKEN'
CHAT_ID = YOUR_CHAT_ID

bot = telebot.TeleBot(TOKEN)

bot.send_message(CHAT_ID, "I'm a big fat dick")

photo = open('img/wobi_512.png', 'rb')
bot.send_photo(CHAT_ID, photo)


@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
    bot.reply_to(message, "Howdy, how are you doing?")


@bot.message_handler(func=lambda message: True)
def echo_all(message):
    bot.reply_to(message, message.text)


bot.polling()

				
			

Python – KivyMD Fonts

Table of Contents

Intro

How to get in KivyMD your Costum Font running with a easy example Code.

Basic Code

				
					from kivymd.font_definitions import theme_font_styles
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.text import LabelBase
KV = '''
Screen:

    MDLabel:
        text: "Rubik"
        halign: "center"
        font_style: "Rubik"

'''


class MainApp(MDApp):
    def build(self):
        LabelBase.register(
            name="Rubik",
            fn_regular="../assets/fonts/Rubik/Rubik-Regular.ttf")

        theme_font_styles.append('Rubik')
        self.theme_cls.font_styles["Rubik"] = [
            "Rubik",
            16,
            False,
            0.15,
        ]
        return Builder.load_string(KV)


MainApp().run()
				
			

Python – Threading

Table of Contents

Start

				
					import threading
import time

def Evennum():
    for i in range(2, 10, 2):
        time.sleep(1)
        print(i)

threading.Thread(target=Evennum).start()