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 / topside_position.py
Last active July 23, 2022 14:26
How to position a topside relative to another widget with and without titlebar
import tkinter as tk
from tkinter import ttk
"""
The demo shows how to position a topside window relative to a button widget from multiple directions. The purpose
is to show that one could theoretically create a custom menu from a toplevel that could be positioned correctly
aligned to the parent widget with and without a titlebar.
The problem with positioning a topside relative to another widget is due to the fact that, normally, window
decorations are added to the window. This adds additional horizontal a vertical space that is not accounted for in
@israel-dryer
israel-dryer / cursor_enum.py
Created June 30, 2021 15:53
tkinter cursor enum
class Cursor:
"""The cursor shown when the mouse is over the widget."""
ARROW='arrow'
BASED_ARROW_DOWN='based_arrow_down'
BASED_ARROW_UP='based_arrow_up'
BOAT='boat'
BOGOSITY='bogosity'
BOTTOM_LEFT_CORNER='bottom_left_corner'
BOTTOM_RIGHT_CORNER='bottom_right_corner'
@israel-dryer
israel-dryer / fedex_shipping_status.py
Created May 23, 2021 20:17
Request FedEx Shipping Status
import requests
def shipping_status(tracking_num):
"""Request shipment status via tracking number.
Args:
tracking_num (int): The FedEx tracking number assigned to the shipment.
"""
url = "https://www.fedex.com/trackingCal/track"
headers = {
@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.
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 / 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)
@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 / 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 / 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 / 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