Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
vigilantPotato / message_aspect.py
Created August 31, 2024 21:51
set aspect ration of message widget
import ctypes
import tkinter
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
comment = "MessageとLabelの違いを確認する。"
#Message: aspect=default(150)
@vigilantPotato
vigilantPotato / difference message and label.py
Created August 31, 2024 21:30
Difference between message and label widgets
import ctypes
import tkinter
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
comment = "MessageとLabelの違いを確認する。"
#Message
m = tkinter.Message(root, text=comment, bg="lightblue")
@vigilantPotato
vigilantPotato / move_main_window_to_monitor_edge.py
Created June 19, 2024 20:57
How to move main window to monitor edge
import ctypes
import tkinter
def up_left():
gap_x = root.winfo_x() - root.winfo_rootx()
root.geometry("+%d+%d" % (gap_x, 0))
def up_right():
x = root.winfo_screenwidth()- root.winfo_width()
@vigilantPotato
vigilantPotato / centering_main_window.py
Created June 18, 2024 21:20
centering tkinter main window
import ctypes
import tkinter
def centering_main_window(event):
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
window_width = root.winfo_width()
window_height = root.winfo_height()
x = screen_width / 2 - window_width /2
@vigilantPotato
vigilantPotato / geometry_2.py
Created June 16, 2024 20:32
How to show main window's size and location individually
import ctypes
import tkinter
def show_geometry_info(event):
width = "w " + str(root.winfo_width()) + "\n"
height = "h " + str(root.winfo_height()) + "\n"
x = "x " + str(root.winfo_x()) + "\n"
y = "y " + str(root.winfo_y())
geo_info["text"] = width + height + x + y
@vigilantPotato
vigilantPotato / geometry_1.py
Last active June 12, 2024 21:38
How to show main window's size and location
import ctypes
import tkinter
def show_geometry_info(event):
geo_label["text"] = root.geometry()
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
@vigilantPotato
vigilantPotato / show_image_with_filedialog.py
Last active June 8, 2024 21:21
How to show image selected by filedialog module
import ctypes
import tkinter, tkinter.filedialog
class ImageViwer():
def __init__(self, root):
#image viwer label
self.image_label = tkinter.Label(
root,
bg="lightblue",
@vigilantPotato
vigilantPotato / filedialog_1.py
Last active June 8, 2024 20:49
How to use filedialog_1
import ctypes
import tkinter, tkinter.filedialog
def get_filepath():
filepath = tkinter.filedialog.askopenfilename(
title="slect txt file",
filetypes=[("txt files", "*.txt")],
)
filepath_result["text"] = filepath
@vigilantPotato
vigilantPotato / windows_volum_setting_scale.py
Created June 3, 2024 21:03
Master volume setting scale for windows
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
import ctypes
import tkinter
class MasterVolumeSettingScale(tkinter.Scale):
def __init__(self, root):
super().__init__(
root,
@vigilantPotato
vigilantPotato / scale_2.py
Created June 3, 2024 21:02
How to use scale widget_2
import ctypes
import tkinter
def get_value():
current_value = scale.get()
b1["text"] = current_value
def set_value():
scale.set(0)