[Python] Tkinter program does not place text

Discussão em 'Python' iniciado por Stack, Agosto 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a tkinter program that should place text. It does not. Why? The canv calls addText(), but the text does not show. I also tried not using my custom module, but still no effect.

    import tkinter as tk
    import terkinter as tr
    import os
    import re

    win = tk.Tk()
    allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
    win.title("Terminos")
    canv = tr.Trk(win,15,30)
    canv.addText(6,6,"hello world!")
    canv.canvas.create_text(canv.screenwidth-5,canv.screenheight-5,text=f"hello world!")
    win.geometry(f'{canv.screenwidth}x{canv.screenheight}')

    win.mainloop()



    Why isn't the text showing? The terkinter module is as follows:

    import tkinter as tk

    class Trk:
    """
    The class of creating
    a canvas, and
    easily manipulating it
    with the TUI functions.
    """
    global screenWidth, screenHeight
    def __init__(self,win,blocksx,blocksy,bg="#232627"):
    self.screenwidth = win.winfo_screenwidth()
    self.screenheight = win.winfo_screenheight()
    self.canvas = tk.Canvas(win,width=self.screenwidth,height=self.screenheight,background=bg)
    self.canvas.pack()
    self.background = bg
    self.parent = win
    self.winwidth = win.winfo_width()
    self.winheight = win.winfo_height()
    self.width = self.canvas.winfo_width()
    self.height = self.canvas.winfo_height()
    self.blockx = blocksx
    self.blocky = blocksy
    self.blocks = self.blockList()
    def coordinate(self,row,col):
    return row*self.blockx, (self.winheight-col)*self.blocky
    def blockList(self):
    li = []
    for i in range(self.blockx):
    tmp = []
    for j in range(self.blocky):
    tmp.append(None)
    li.append(tmp)
    return li
    def addText(self,row,col,text,font="1:1",color="white"):
    row, col = self.coordinate(row,col)
    self.canvas.create_text(row,col,text=text,fill=color)
    def kill(self):
    self.canvas.destroy()

    Continue reading...

Compartilhe esta Página