r/Tkinter • • Dec 04 '22

I don't know how to update my Label?

0 Upvotes

from tkinter import *
import time as t
import tkinter
from tkinter import ttk
root = tkinter.Tk()

lbl = tkinter.Label(root,text="how many seconds?:")
lbl.grid(row=0,column=0)
root.geometry('400x300')
root.resizable(False,False)
lbl_enter = ttk.Entry(root)
lbl_enter.grid(row=1,column=0)
lbl2 = tkinter.Label(root,text=str(0)+"seconds")
lbl2.grid(row=4,column=0)
def run():

inputtime = 0
amount = int(lbl_enter.get())

while inputtime < amount:
inputtime += 1
input = inputtime
t.sleep(1)
print(str(inputtime))
lbl2 = tkinter.Label(root,text=str(input)+"seconds")
lbl2.grid(row=4,column=0)

btn_amount = ttk.Button(root,text="done", command = lambda: run())
btn_amount.grid(row=2,column=0)

root.mainloop()


r/Tkinter • • Feb 12 '26

New

0 Upvotes

I've heard about this app a few years, but never really know what it was or what it's about. Can someone explain to me?


r/Tkinter • • Jul 01 '22

I can't get both labels and frames in the same function

0 Upvotes

So I'm trying to make a to do list where you could add, delete and move the to do thing. I want to be able to have buttons an image and some text on one frame that would be inside the global frame for all the things, but i can't generate the labels and the frame in a function. either one of them just dissappears when I change things. Here is the latest try :

from tkinter import *
from PIL import ImageTk, Image


class Root(Tk):
    def __init__(self):
        Tk.__init__(self)
        self.title("To-do list")
        self.geometry('1000x800')
        self.configure(bg="#000000")
        self.to_do_list = []
        self.label_list = []

        # label & Entry boxes territory
        #       nameLb = Label(ws, text="Enter Your Name", pady=15, padx=10, bg='#567')
        self.text_frame = Frame(self, width=300, height=50, background="#FFFFFF", border=False)
        self.text_area = Entry(self.text_frame, font="Calibri 20", border=False, background="#EEEEEE")
        self.line_frame = Frame(self, width=300, height=3, background="#FFFFFF", border=False)
        self.container = Frame(self, width=350, height=500, background="#DEDEDE")

        self.line_image = ImageTk.PhotoImage(Image.open("assets\line.png"))
        self.button_image = ImageTk.PhotoImage(Image.open("assets\+.png"))

        self.line = Label(self.line_frame, image=self.line_image, border=False)

        # button territory
        self.add_button = Button(self, image=self.button_image, command=self.add, borderwidth=-1, relief=FLAT, border=False)

        # Position Provide territory
        #       nameLb.grid(row=0, column=0)
        self.add_button.place(x=50, y=50)
        self.text_frame.place(x=100, y=50)
        self.text_area.place(x=10, y=7)
        self.line_frame.place(x=100, y=98)
        self.line.place(x=0, y=0)
        self.container.place(x=50, y=110)

        # infinite loop

    # function territory
    def add(self):
        order = len(self.to_do_list)+1
        self.to_do_list.append(Frame(self.container, bg='#FFFFFF', border=False, width=346, height=50))
        todo = self.text_area.get()
        container = self.to_do_list[-1]
        self.label_list.append(Label(container, text=f'{todo}'))
        return self.reload()

    def reload(self):
        for i in range(len(self.to_do_list)):
            self.to_do_list[i].place(x=2, y=i * 52)
        for i in range(len(self.label_list)):
            self.label_list[i].pack()

if __name__ == "__main__":
    Root().mainloop()

r/Tkinter • • May 14 '22

Very basic question about keybinds

0 Upvotes

Hey, I've seen on SO that keybinds must all be done in separate binds, but I'm just curious as to why this function doesn't work:

def l(event):
    if(event=="<Left>" or "a" or "A"):
        root.bind("", left)

Thanks!


r/Tkinter • • Dec 24 '24

TkinterDnD2 Drag and Drop Not Working Correctly from VS Code

0 Upvotes

I'm encountering a frustrating issue with TkinterDnD2 where drag and drop works flawlessly from the system explorer (e.g., Windows File Explorer) and even other applications like Android Studio, but it fails to import file paths correctly when dragging files from VS Code. Specifically, while the drag operation is detected, the actual file data is not being received, resulting in files not being imported into the application.

Here's the relevant code setup for my drag-and-drop functionality:

```python

from tkinterdnd2 import DND_FILES, TkinterDnD

import logging

logging.basicConfig(filename="file_combiner.log", level=logging.INFO,

format="%(asctime)s - %(levelname)s - %(message)s")

class FileCombinerApp:

def __init__(self, root):

self.root = root

self.setup_drag_and_drop()

def setup_drag_and_drop(self):

# Register the main window for drag and drop

self.root.drop_target_register(DND_FILES)

self.root.dnd_bind('<<Drop>>', self.on_drop)

self.root.dnd_bind('<<DropEnter>>', self.on_drop_enter)

self.root.dnd_bind('<<DropLeave>>', self.on_drop_leave)

self.root.dnd_bind('<<DragPosition>>', self.on_drag_position)

```

I'm using these logging methods to capture the drag-and-drop events:

```python

def on_drop(self, event):

# Log raw drag data for debugging

raw_data = event.data

logging.info(f"RAW DROP EVENT DATA : {raw_data}") # Debugging: Shows the exact data received

def on_drop_enter(self, event):

logging.info("Drag operation entered drop target")

def on_drop_leave(self, event):

logging.info("Drag operation left drop target")

def on_drag_position(self, event):

logging.info(f"Drag position: x={event.x_root}, y={event.y_root}")

```

**The Issue:**

* **System Explorer (and Android Studio) Works:** When I drag a file from the system explorer or Android Studio, the `on_drop_enter`, `on_drop_leave`, and `on_drag_position` events are triggered (I see the corresponding logs in `file_combiner.log`), and importantly, I *also* get the `RAW DROP EVENT DATA` logged, and files are correctly added to my application.

* **VS Code Fails:** When I drag a file from VS Code, I *do* see the `on_drop_enter`, `on_drop_leave`, and `on_drag_position` events being triggered correctly, which shows that `TkinterDnD2` is capturing the drag itself. However, crucially, I do *not* see any `RAW DROP EVENT DATA` being logged in the `on_drop` method. This indicates that while the drag is detected, VS Code is *not* sending the file paths, and I am not receiving any data.

It appears that the `<<Drop>>` event from VS Code is either not sending the expected data or is using some custom internal format, which `TkinterDnD2` cannot interpret as file paths.

**My Question:**

Has anyone encountered this specific behavior with TkinterDnD2 and VS Code? I've tried all the debugging I know to use, and I can't seem to get VS Code to send file paths, even though the drag is detected correctly.

_This VS Code drag-and-drop functionality is an integral part of my application's workflow, and I've been very happy with Tkinter so far. However, if I can't find a way to make this work consistently, I'll have no choice but to look into other options like PyQt/PySide or PyWin32. Any guidance would be extremely helpful._

Here the repo.

Thanks in advance!


r/Tkinter • • Dec 19 '21

Frame ( ) function doesn't work

0 Upvotes

hello!

I am a beginner with Tkinter, Python, and programming generally...

I have watched a tutorial on how to make frames with Tkinter which is by the function Frame( ) but it doesn't work... I have tried many times but it always tells me that the name Frame is undefined...

any help..?


r/Tkinter • • Aug 05 '21

Why does tkinter look so bad?

2 Upvotes

Is there any way I can make a good and modern looking gui with tkinter?


r/Tkinter • • Jan 11 '21

TK QUI PÈTE

Thumbnail
youtube.com
0 Upvotes

r/Tkinter • • Oct 07 '25

I finally finished a big project to fund my college degree: A hands-on guide to building 10 desktop apps using ONLY standard Python (Tkinter). What are your favorite Tkinter projects?

1 Upvotes

I've been working on a massive project for the last few months to help pay for my university education, and I wanted to share the final result with this community: THE TKINTER QUICKSTART: Your First 10 Python Applications.

I know many of us Python users struggle to transition from command-line scripts to visual tools. I decided to master Tkinter—the simplest, pre-installed library—and create a guide based entirely on 10 practical projects (not just theory!).

What makes this different (and why I think you should check it out):

  • Project-Based Learning: We don't just talk about widgets; we build 10 functional apps: a Password Generator, To-Do List, Unit Converter, etc.

  • Modern Tkinter: I dive deep into the ttk styling module to make sure the apps look modern and native, avoiding that "old-school" look.

  • Layout Mastery: If you've ever struggled with messy layouts, I dedicated a full section to mastering the professional grid() manager.

  • Zero Risk, Real Support: If the book doesn't meet your expectations, the platform offers a 7-day money-back guarantee, no questions asked.

This project means the world to me as it directly supports my college expenses. If you are interested in giving it a look, you can find the link in my first comment below or on my profile.

Any shares or advice on promoting it in a non-spammy way would be incredibly appreciated! Thanks for checking it out.


r/Tkinter • • Dec 31 '21

Widgets in Tkinter Frame Not Properly Sizing

1 Upvotes

So I have this problem with my tkinter script and nothing will properly resize. Grid's anchor & sticky don't work, Pack's fill & side don't work. I don't understand why as I've worked with these tools before. Any help appreciated!

root = tk.Tk()
root.title("Match")
root.geometry("450x500")
root.update()

button_frame = ttk.Frame(root, width=root.winfo_width(), height=root.winfo_width())
button_frame.grid(row=0, column=0)
button_frame.update()

option_frame = ttk.Frame(root, width=root.winfo_width(), height=root.winfo_height() - root.winfo_width(), padding=(0,5,0,0))
option_frame.grid(row=1, column=0)
option_frame.update()

ttkbootstrap.Style("superhero")

#ttk.Separator(option_frame, orient="horizontal").grid(row=1, column=0, columnspan=1, sticky='e')
ttk.Button(option_frame, text="Disconnect").grid(column=0, row=0, sticky='e')
ttk.Button(option_frame, text="Disconnect").grid(column=1, row=0, sticky='w')

root.mainloop()


r/Tkinter • • Jun 02 '20

Tkinter in simple words

Thumbnail
itvoyagers.in
1 Upvotes

r/Tkinter • • Apr 17 '19

AttributeError: 'str' object has no attribute 'tk'

1 Upvotes

Title (line 21). I have been trying to create a text box, but Python is yelling at me. Code:

import tkinter

from tkinter import *

class Interface(Frame):

def __init__(self, master=None):

super(Interface, self).__init__()

Frame.__init__(self, master)

self.init_window()

def quit():

window.destroy()

def init_window(self):

self.master.title('Communications Interface')

self.pack(fill=BOTH, expand=1)

self.configure(background = 'black')

quitButton = Button(self, text='Quit', bg = 'black', fg = 'green', activebackground = 'black', activeforeground = 'red', command = quit)

quitButton.place(x=0, y=0)

def recvAndDisplay(self):

global allMsgs

msgs = Text(self, height = 400, width = 600, bg = 'black', fg = 'green', )

msgs.pack(side=LEFT, fill=Y)

scrollBar = Scrollbar(self, bg = 'black', fg = 'green', activebackground = 'green', activeforeground = 'black')

scrollBar.pack(side=RIGHT, fill=Y)

scrollBar.config(command=msgs.yview)

msgs.config(yscrollcommand=scrollBar.set)

while True:

msgs.insert('\\n', END, msg)

allMsgs = []

window = Tk()

window.geometry('800x500')

app = Interface(window)

window.mainloop()

msg = 'Test'

Interface.recvAndDisplay(msg)

msg = 'Test2'

Interface.recvAndDisplay(msg)


r/Tkinter • • Feb 04 '22

Hi!!!!!

Post image
1 Upvotes

r/Tkinter • • Jun 04 '23

How do I make Something like this in Tkinter?

Post image
1 Upvotes

r/Tkinter • • Feb 26 '23

Why won't my image open in Tkinter GUI?

1 Upvotes

I'm pretty new to python and have been try put an image on a Tkinter GUI window. I'm on macos and use Visual Studio Code to run it. But when running the code it says:
Traceback (most recent call last):

File "/Users/Daniel/VS-Code-Python/test.py", line 5, in <module>

image_0=Image.open('\\Users\\Daniel\\VS-Code-Python\\testimg.png')

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/Image.py", line 3227, in open

fp = builtins.open(filename, "rb")

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

FileNotFoundError: [Errno 2] No such file or directory: '\\Users\\Daniel\\VS-Code-Python\\testimg.png'

Here is the code:

  1. from tkinter import *

  2. from PIL import ImageTk, Image

  3. root = Tk()

  4. root.title=("Test")

  5. image_0=Image.open('\\Users\\Daniel\\VS-Code-Python\\testimg.png')

  6. image=ImageTk.PhotoImage(image_0)

  7. root.geometry=("780x520")

  8. lbl=Label(root, image=image)

  9. lbl.place(x=0,y=0)

  10. root.mainloop()
    Traceback (most recent call last):

Please tell me what is wrong with my code or what I can do to fix this.


r/Tkinter • • Nov 02 '21

Test for takeoff.

0 Upvotes

r/Tkinter • • Jul 10 '21

Should I create a 2D game in Python/ Tkinter?

2 Upvotes

I am very familiar with Tkinter and I would like to create a 2D game with it although I am concerned. I understand python is not the best language for it and it may end up being slow but the game won't be that complicated. Do you think I should go for it?

I will later use pyinstaller to turn it into an executable and hopefully get it on Steam. Thoughts?


r/Tkinter • • Dec 04 '21

Python Tkinter Clock Function Stops Updating After Some Time

2 Upvotes

I have an app with a function that updates a canvas text widget with the time every second. For some odd reason, after say 60min, it just hangs. It can be the function or Datetime. It fixes itself when I click the screen or interact. I seriously have zero idea what can be causing it.

Any help appreciated!


r/Tkinter • • May 11 '22

blank window keeps popping up

2 Upvotes

hi i need help, i'm currently making a light novel type video game with tkinter so i'm basically opening new windows depending on the choice button clicked but every time i click on a button and open up a new window, a blank pop up opens up, i tried using root.withdraw but it doesn't work and i cen't figure out how to get rid of that help (the answer is probably fairly simple but i really am not the best at coding-)


r/Tkinter • • Jul 19 '21

i want to add list of songs in tkinter

0 Upvotes

r/Tkinter • • May 09 '24

Remove the Border of a Button

Post image
3 Upvotes

Hello everyone I’m currently working on a Programm with Tkinter. I have changed the color of my screen and Buttons, but there is still this gray border. I have already tried the borderwidth=0 command, but it didn’t work. Does anybody know how to solve this problem? (I’m using a raspberry pi)

Thank you


r/Tkinter • • Sep 01 '21

average tkinter enjoyer

Post image
18 Upvotes

r/Tkinter • • Apr 14 '25

ModuleNotFoundError: No module named 'tkinter' - Visual Studio Code Python

0 Upvotes

You know when I had this problem even chatgpt recommended just reinstalling Python.

However, that isn't that necessary as it turns out that certain extensions (I am unsure which one) can have an interpreter already in the application, and due to this it can run your code using an interpreter you didn't mean to use

I recently had 3.12.5 and then installed 3.13.3 but I still had the same error message. It was only after I looked at the very bottom of the application did I noticed that the interpreter I used was not the same version as what I had just installed especially as I wasn't even sure if I had properly linked Python with VS Code so I clicked on it then it gave 2 options on the search bar saying "3.7.4 Global" which was the automatic one and "3.13.3 Recommended" which was the one I had installed and after I made the switch did turtle suddenly start working

So for everyone experiencing this before you think of reinstalling Python check if the version of the interpreter you are using is the one YOU installed via the website for Python and not the one from the extension or just possibly preinstalled in VS Code


r/Tkinter • • Jun 14 '25

Why I cannot load an icon even if pic and code is in the same folder

0 Upvotes

Error:

_init__.py", line 4111, in __init__

self.tk.call(('image', 'create', imgtype, name,) + options)

_tkinter.TclError: couldn't open "IroIcon.png": no such file or directory

Code:

from tkinter import *
 
root = Tk()
icon = PhotoImage(file = "IroIcon.png")
root.iconphoto(False, icon)
root.title("IRONote")
root.geometry("720x720")
 
root.mainloop()

r/Tkinter • • Jul 08 '21

Dictionary app using python tkinter

Thumbnail
youtu.be
4 Upvotes