This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A cx_freeze setup script that works for executables for python 3.5+ based | |
apps that use the tkinter graphics framework. | |
i.e. fixes the "KeyError: 'TCL_Library'" error | |
""" | |
import os | |
import sys | |
from cx_Freeze import setup, Executable | |
# set location tkinter path variables using os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
An examnple of the use of threading to allow simultaneous operations in a | |
tkinter gui (which is locked to a single thread) | |
""" | |
import threading | |
import tkinter as tk | |
from tkinter import ttk | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A comparison of methods for rounding upwards on dvision operations. Suprisingly, the fastest method was multiplying | |
the numerator in the division operation by negative one, using floor division, and then multiplying again by | |
negative one to arrive at the rounded up answer | |
Further testing is required on larger numbers (and maybe complex numbers?) to see if the results scale well. | |
""" | |
import math | |
import numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
a = itertools.cycle(range(3)) | |
letters = "ABCDEFG" | |
for num, alpha in zip(a, letters): | |
print(f"{num} - {alpha}") # f-strings are awesome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
An improvement on the tkinter Checkbar example, | |
available from http://www.python-course.eu/tkinter_checkboxes.php | |
Author: Matt Woodhead | |
""" | |
import tkinter as tk | |
from tkinter import ttk | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
def explorer_on_file(url): | |
""" opens a windows explorer window """ | |
subprocess.Popen(f'explorer /select,"{url}"') | |
explorer_on_file(r"C:\Python\python.exe") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
def ip_check(): | |
""" uses the cockets module to find the local IP address """ | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect(("8.8.8.8", 80)) # Ping Google DNS server | |
ip_address = s.getsockname()[0] | |
s.close() | |
return ip_address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def caseless_dict_search(dictionary, search_string): | |
""" performs a case insensitive key search on a standard dictionary """ | |
# A dict matching lower case and actual case representations of the Keys | |
keys_dict = {k.casefold(): k for k in dictionary.keys()} | |
# Using the get() function to search dict with builtin error handling | |
return dictionary.get(keys_dict.get(search_string.lower(), None), None) | |
test_dict = {"A": 0, "B": 1, "c": 2, "d":3} | |
INPUT = "D" # Note case does not match any of the keys in the above dict | |
result = caseless_dict_search(test_dict, INPUT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Easier to ask forgiveness than permission """ | |
my_dict = {"key_0": 0, | |
"key_1": 10, | |
"key_2": 20, | |
"key_3": 30, | |
"key_4": 40, | |
} | |
OlderNewer