Tk Source Code

Artifact [888ab6a4]
Login

Artifact 888ab6a4aff05d7fa659a1b8f5999f71ca9a11d6a7ca1f283e6d5cb4d3b3cbd8:

Attachment "test.py" to ticket [eb1c56bf] added by anonymous 2026-10-02 08:51:08. (unpublished)
import tkinter as tk, tkinter.font as tkfont, sys

root = tk.Tk()
root.geometry("400x260")
if len(sys.argv) > 1:
    root.tk.call("tk", "scaling", float(sys.argv[1]))

b = tk.Button(root, text="Plain Tk button", padx=20, pady=10)
b.pack(padx=30, pady=(20, 10))
c = tk.Canvas(root, width=300, height=100, highlightthickness=0, bg="#2b2b2b")
c.pack(pady=10)
c.create_text(150, 50, text="Canvas test", fill="white", font=("Roboto", 14))

def report():
    f = tkfont.Font(family="Roboto", size=14)
    print("tk scaling", root.tk.call("tk", "scaling"))
    print("text width", f.measure("Canvas test"), "linespace", f.metrics("linespace"))
    print("button width", b.winfo_reqwidth(), "canvas width", c.winfo_reqwidth())
root.after(500, report)
root.mainloop()