The Python tkinter keys() method for a label

  Рет қаралды 10,293

John Philip Jones

John Philip Jones

Күн бұрын

Пікірлер: 20
@bantuthomas
@bantuthomas 4 жыл бұрын
Mr. Jones, I have found your videos to be of the highest level of clarity and utility. Thanks a ton.
@samiadel7043
@samiadel7043 Жыл бұрын
Great, really I'm shocked sir, you're giving what I was looking for, thank you 💕 God bless you .
@bishtss1
@bishtss1 6 жыл бұрын
Excellent way of teaching, animation makes the concept more clearer and easy to remember.
@bantuthomas
@bantuthomas 4 жыл бұрын
Like Elbichnito has suggested below, could you show if different threads can execute different parts of a tkinter app. Often, a loop with a sleep in one part of the code puts the rest of the code to sleep till that part of the code is competed. An example is given below: from tkinter import * from time import sleep def Timer(): for i in range(5): sleep(1) win = Tk() Timer() btn1 = Button(win, text="Click") btn1.place(x=50, y=50) win.mainloop() Thanks a million for the great work you have done.
@johnphilipjones
@johnphilipjones 4 жыл бұрын
I will be developing a series on threads in Python in the coming months. Best wishes Phil
@KOLLECT0R
@KOLLECT0R 5 жыл бұрын
Would you please make threading, beautiful soup. Sqlite and socket tutorials. The best explanation tutorials ever in youtube. Thank you so much.
@johnphilipjones
@johnphilipjones 5 жыл бұрын
Thank you for your positive comments. The topics you have suggested are in the pipeline. Best wishes Phil Jones
@KOLLECT0R
@KOLLECT0R 5 жыл бұрын
@@johnphilipjones I am a self taught and I did not know what you meant by the pipeline.
@johnphilipjones
@johnphilipjones 5 жыл бұрын
"in the pipeline" is an English saying. It means in the process of being planned. In this case I will in the near future be developing videos on the topics you have suggested. Best wishes Phil
@KOLLECT0R
@KOLLECT0R 5 жыл бұрын
@@johnphilipjones thank you so much for your time and effort.
@oldreddragon1579
@oldreddragon1579 6 жыл бұрын
Hi, just tried the underline with a value of 2 and saw that the letter "l" in "Hello World" was underlined so I was wondering if it has anything to do with hotkeys? BTW This series has been really informative so thanks.
@johnphilipjones
@johnphilipjones 6 жыл бұрын
Thank you for the positive comments. The underline is useful when using it with a button as it allows you to invoke the mouse click event of the button with appropriate key-presses. Regards Phil
@dimitriosdesmos4699
@dimitriosdesmos4699 5 жыл бұрын
Hello, how can I access the Label help files in order to read the documentation on each Key/Value combination ? thank u
@johnphilipjones
@johnphilipjones 5 жыл бұрын
You may find this link useful: docs.python.org/3.7/library/tkinter.html?highlight=label%20options
@rickybeeSE
@rickybeeSE 5 жыл бұрын
I am trying to use this technique to change an image assigned to a label. But I get the error str object does not support item assignment.
@johnphilipjones
@johnphilipjones 5 жыл бұрын
Can you paste the code as a reply Thanks Phil
@rickybeeSE
@rickybeeSE 5 жыл бұрын
@@johnphilipjones Thanks for the reply. Unfortunately I cannot simply paste the code here as it is about 250 lines currently and contains information on a layout of a secure, private network. The program works but my problem has been that it crashes, out of memory, in a few hours. I have 150 icons that need to change between 3 states periodically. And when you create a new label in tkinter it uses memory, and that memory is not released if a new label is placed on top. So with each change memory is used. With text on a label you can use StringVar(), what's needed is the equivalent ImageVar(). I have done some further tests using the technique in this video and they do work, so I am now thinking that the error I'm getting is being caused by this statement getting bad information. I'll need some more time to figure this out.
@rickybeeSE
@rickybeeSE 5 жыл бұрын
@@johnphilipjones I put together a simple program to illustrate the problem with using the key variable for images in labels, which gives the error I mentioned in the original post. If you have time I'd really like your input on this, if it can be made to work, or if there's another way to accomplish the same thing. TIA import tkinter as tk import time window = tk.Tk() window.title("PiStatus") window.geometry("500x500+0+0") ct = 0 pc_on_icon = tk.PhotoImage(file="1.png") pc_active_icon = tk.PhotoImage(file="2.png") pc_off_icon = tk.PhotoImage(file="0.png") # This loop creates the base 15x10 grid of labels, each with a unique name. for ypos in range(10): for xpos in range(15): label_name = "icon" + str(xpos) + "-" + str(ypos) label_name = tk.Label(window, image=pc_on_icon) label_name.grid(row=ypos, column=xpos) while True: # These statements cycle through the 3 images if ct == 0: turn = pc_off_icon elif ct == 1: turn = pc_on_icon else: turn = pc_active_icon # This loop references each label giving it a different image each time around for ypos in range(10): for xpos in range(15): label_name = "icon" + str(xpos) + "-" + str(ypos) label_name['image'] = turn # this is where the error occurs. ct += 1 if ct == 3: ct = 0 window.update() window.mainloop()
@rickybeeSE
@rickybeeSE 5 жыл бұрын
This has been solved. It's been a learning experience getting my head around how labels work, that if you set Label_1=...... you can't push an element into Label_1, it is not a variable. You have to create a reference to what comes after Label_1 and keep it in memory. What I did was create a list that contains an ID based on the x/y co-ords of the label position, then the label. Appending these two items to the list for each label. Then later in the program I can reference the ID and the label is the next element.
@johnphilipjones
@johnphilipjones 5 жыл бұрын
Hello Richard, Sorry I did not get back to you in time but glad you have now solved it. Best wishes Phil
Using StringVar and textvariable with a Python tkinter label
9:50
John Philip Jones
Рет қаралды 45 М.
The Entry widget and StringVar()
18:54
John Philip Jones
Рет қаралды 23 М.
Triple kill😹
00:18
GG Animation
Рет қаралды 13 МЛН
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 251 МЛН
Это было очень близко...
00:10
Аришнев
Рет қаралды 7 МЛН
The Python tkinter StringVar set() method
8:43
John Philip Jones
Рет қаралды 18 М.
How to Inherit from a Python tkinter Frame
31:12
John Philip Jones
Рет қаралды 25 М.
How To Make Your Matplotlib Bar Charts Stand Out
19:59
Andy McDonald
Рет қаралды 2,1 М.
Introduction to the Python tkinter button widget
11:10
John Philip Jones
Рет қаралды 14 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 411 М.
Focus and Tab order of Widgets in a Python GUI
13:23
John Philip Jones
Рет қаралды 10 М.
Using the Python help function to assist with inheritance
18:10
John Philip Jones
Рет қаралды 5 М.
Functional Programming in 40 Minutes • Russ Olsen • GOTO 2018
41:35
GOTO Conferences
Рет қаралды 816 М.
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 448 М.
Triple kill😹
00:18
GG Animation
Рет қаралды 13 МЛН