Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to make a simple timer kind of GUI application using the python tkinter module.
The requirements of my application are
Should have no buttons.
It must have a dynamic field that shows the time taken in seconds.
I have searched a lot but wasn't able to conclude.
So, expecting whether can my requirement be met using Tkinter?
If yes, wishing to know the way of achieving it.
If no, can my requirement be met using any other python or other GUI libraries?
Thanks in advance.
Yes this can be achieved with tkinter, take a look at this example below:
from tkinter import * #importing
import time
root = Tk() #creating a window
def change():
l.config(text=time.ctime()) #update the text on the label
root.after(500,change) #repeat the function each 500 ms
l = Label(root, text='Hello world',font=(0,20)) #creating a label on window
l.pack() #putting it on the window
change() #calling the function initially
root.mainloop() #putting it inside a loop
Note that your calling this function each second, which might not be efficient, this is will work for small projects and its here to just give you an idea.
Hopefully you get a idea of whats going on here, I recommend you watch a detailed video on tkinter and proceed to work with it.
Related
I am looking to see if i could get some help and insight on the issue i am having thank you.
I have a program that runs and displays a Tkinter window with a button and a textbox (This works as intended) and the textbox is populated by (self.T.insert(tk.END,"text") and the button calls the class TwitchBot(irc.bot.SingleServerIRCBot).
The first issue i have is that when the class TwitchBot(irc.bot.SingleServerIRCBot) is called the tkinter window freezes.
i think as its a diffrent class, but am unfamillar with tkinter
The second issue is in the class TwitchBot(irc.bot.SingleServerIRCBot) i would still like to populate the textbox with (self.T.insert(tk.END,"text")
i tried to put the code here but it wasnt working well. so uploaded to github
https://github.com/isrever/bot/blob/main/bot.py
I have a GUI based in Python 3 and tkinter that has a big ttk.Treeview. I have defined methods for row selection (one click) and opening an advanced info panel (double-click). I need to ensure that, after being double-clicked, for the next one or two seconds, the Treeview state won't be changed by another click. Is it possible to deactivate Treeview mouse bindings, like what we do with buttons?
Doing a little more research, I was able to come up with a solution for this. I just created an empty method that is called when the tree widget is supposed to be inactive. So, we can use something like this to "unbind" all the mouse events and re-bind them a few seconds later, as needed:
def nothing(self, *event):
""" # Hacking moment: A function that does nothing, for those times you need it...
"""
pass
def bind_tree(self):
""" # Bind mouse and keyboard events to their respective functions or methods...
"""
self.tree.bind('<<TreeviewSelect>>', self.selectItem_popup)
self.tree.bind('<Double-1>', self.show_details)
self.tree.bind("<Button-2>", self.popupMenu)
self.tree.bind("<Button-3>", self.popupMenu)
def unbind_tree(self):
""" # Unbind all mouse and keyboard events, by binding them to an empty method...
"""
self.tree.bind('<<TreeviewSelect>>', self.nothing)
self.tree.bind('<Double-1>', self.nothing)
self.tree.bind("<Button-2>", self.nothing)
self.tree.bind("<Button-3>", self.nothing)
Then, in the rest of the code, We only need to call bind_tree() and unbind_tree() as needed.
This worked for me:
tree.bind("<ButtonRelease-1>", my_select_function)
# Do some stuff
tree.unbind("<ButtonRelease-1>")
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In c# 4.0 I would like to set, at an application level, a default caption for any message boxes the program creates. And by caption I mean the title of the message box.
So should a error message be displayed to the user they will all have the same title.
I know I can do it by using this Message Box overload:
MessageBox.Show(errorMessage, caption);
But I am wondering if there is a more crisp, clean, way to do it?
Rather than having to add a parameter to lots of calls?
You can't really set a default. But you can make a helper to set the title for you, if you really want
public static class MessageBoxEx
{
public static void Show(string message)
{
MessageBox.Show(message, "My Application Name");
}
}
You can of course set the caption however you want, such as from a resource file for multiple languages and locales.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm a beginner in Android Studio and am trying to figure out how to edit different layouts(.xml files) with one java class(.java). I am trying to get the id of an ImageView on another layout, but the findViewById of the ImageView returned null. What do I need to do? Also, I have two layout files because I am using a popupWindow. So, I need to access the ImageView of the popupWindow.
Thanks!
It sounds like you are just using Activity's findViewById, which would search the activity's layout for your ImageView. You would need to call findViewById on your inflated popup view:
View popupView = getLayoutInflater().inflate(R.layout.popup, null);
//Get your image view from the inflated popup
ImageView image = (ImageView) popupView.findViewById(R.id.imageView);
I have a simple tkinter.messagebox.showinfo inside a python code, how can I close the messagebox inside the python code as the code runs?
Thx.
This is not possible as far as I know because the tkinter.messagebox.showinfo waits for user input, which is to click the button. This is what showinfo is supposed to do.
If you want to display something to the user and make it disappear after a while (say a loading... sign) I would suggest using a progrssbar instead of a messagebox.
In any case, you will need another thread to control the functionality of your current thread.
This post may give you more info about using threads this way.
Also note that it's recommended that secondary threads are not given access to tkinter objects.