Skip to content

Instantly share code, notes, and snippets.

View israel-dryer's full-sized avatar

Israel Dryer israel-dryer

View GitHub Profile
@israel-dryer
israel-dryer / full_module_class_instantiation.py
Created February 25, 2021 05:05
Instantiate all the classes in a target module without explicitly naming them
import sys
from datetime import datetime
class GoogleNewsScraper():
def __init__(self):
self.date_modified = datetime.today()
def scrape(self):
@israel-dryer
israel-dryer / fading_window.py
Created March 29, 2021 19:55
A tkinter window that fades in and out at specified intervals
"""
Window that fades in an out at a specified time interval and increment
Author: Israel Dryer
Modified: March 29, 2021
"""
from tkinter import ttk
import tkinter
@israel-dryer
israel-dryer / tearoff.py
Created April 8, 2021 01:42
tkinter startup tearoff menu
import tkinter
def tearoff_callback(menu, tearoff):
"""Move the tearoff menu after tearoff"""
root.update()
x = root.winfo_x() - 75
y = root.winfo_y()
root.tk.call('wm', 'geometry', tearoff, f'+{x}+{y}')
root = tkinter.Tk()
@israel-dryer
israel-dryer / new_ttk_theme.py
Created April 16, 2021 13:42
A simple example of creating a new ttk theme
"""
Author: Israel Dryer
Modified: 2021-04-16
Here's a simple example of creating a new theme with a single custom widget - a modern looking radiobutton.
In this example, I used a dictionary of settings. However, you can just as well do it with the Style.map,
Style.layout, and Style.configure methods. But, if you're going to build an entire theme, then using a settings
dictionary is more scalable, and could technically be stored in an offline json file as well.
"""
from PIL import ImageDraw, Image, ImageTk
@israel-dryer
israel-dryer / outlook_reply.py
Created April 20, 2021 14:46
reply to a message using outlook and python
import win32com.client as client
outlook = client.Dispatch('Outlook.Application')
namespace = outlook.GetNameSpace('MAPI')
inbox = namespace.GetDefaultFolder(6)
# search for messages meeting a specific criteria
target_messages = [item for item in inbox.Items if 'product' in item.Subject]
@israel-dryer
israel-dryer / radial_gauge.py
Created April 21, 2021 15:01
radial gauge for tkinter
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk, ImageDraw
class Gauge(ttk.Label):
def __init__(self, parent, **kwargs):
self.arc = None
@israel-dryer
israel-dryer / save_from_page_to_page.py
Created April 22, 2021 13:01
example of saving text from one tab onto another in tkinter
import tkinter as tk
from tkinter import ttk
def submit(source, dest):
"""Collect data from source text and insert into destination text"""
text = source.get('1.0', 'end')
dest.insert('end', text)
@israel-dryer
israel-dryer / screenshot.py
Created April 22, 2021 21:13
A class to attach to tkinter windows for taking screenshots
import pathlib
from PIL import ImageGrab
class Screenshot:
def __init__(self, parent, filename):
self.parent = parent
self.parent.bind("<Insert>", self.get_bounding_box)
import tkinter as tk
from PIL import Image, ImageTk, ImageDraw
from tkinter import StringVar, IntVar
from tkinter import ttk
from tkinter.ttk import Frame
class NeedleMeter(Frame):
def __init__(self,
@israel-dryer
israel-dryer / sizegrip.py
Created May 19, 2021 12:36
Create a custom sizegrip style
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageDraw, ImageTk
def sizegrip_style(background, foreground):
"""Create style configuration for ttk sizegrip
Args:
background (str): The color used for the background.