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 1 year ago.
Improve this question
I am trying to get my widget to light up when the mouse is hovering over it. Here is what I have tried:
self.buttons = []
self.buttonTips = ["Select and Add a clip to the project", "Order the clips in your project", "Trim the selected clip",
"Cut out audio breaks in the selected clip", "Preview clip (in new window)", "Render/Export your video"]
self.commands = [self.getClipPath, self.reorderClips, self.trimClip, self.cutOutAudio, self._preview, self.finishVideo]
self.images = [_addImage, _switchImage, _trimImage, _autoTrimImage, _previewImage, _exportImage]
for index, tip in enumerate(self.buttonTips):
self.buttons.append(Button(self.root, image=self.images[index], command=self.commands[index], bg=_bgcolor, relief=FLAT))
self.buttons[index].photo = self.images[index]
self.buttons[index].place(x=index * 30, y=490)
self.buttons[index].bind("<Enter>", func=partial(changeButtonBG, 1, self.buttons[index]))
self.buttons[index].bind("<Leave>", func=partial(changeButtonBG, 0, self.buttons[index]))
addToolTip(self.buttons[index], tip)
When I change the event type to <Motion> the function runs perfectly, but when I use or it doesn't work? Anyone know why?
Ok I have figured out my problem. In this line here:
addToolTip(self.buttons[index], tip)
the addToolTip() function also adds a bind to the widget. So I edited the binds so they had:
button.bind(func=function, add="+")
which adding the add="+" made it work
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Is there any way to show the message in popup window that process is running when python script start and disappear the popup window when process is done. Thanks in advance
A very flexible method you could look into is creating a tkinter window:
https://docs.python.org/3/library/tkinter.html
import tkinter as tk
import time
def some_function():
print('Do stuff')
time.sleep(3)
if __name__ == '__main__':
# Create window
window = tk.Tk()
# Create label
label_var = tk.StringVar()
label_var.set('Program is running...')
label = tk.Label(window, textvariable=label_var)
label.pack()
# Update and show window once
window.update_idletasks()
window.update()
# Your function code
some_function()
# Get rid of window
window.destroy()
Edit: just saw someone answered with tkinter in the comments... will leave this here as an example
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
#writing introduction text
mn=tk.Label(window,text="WELCOME TO \n AAROGYA SETU \n SELF EXAMINATION FRONT",font=("Bookman old style",30,'bold','italic')).pack()
#linking sign up form
sig=tk.Label(window,text="click button to sign up",font=("Bookman old style",20,"bold")).pack()
Error message:
'Nonetype' has no attribute .grid()
I am unable to position my label (that I created using Tkinter) in my program. it doesn't take .grid() or .place() either.
What can be the possible reasons? my code execution otherwise is perfect.
You do the most common mistake
variable = Widget().pack()
which assign None to variable because pack()/grid()/place() returns None.
You have to do it in two steps:
variable = Widget()
variable.pack()
But it seems you may create other problem.
pack()/grid()/place() are different layout managers and you shouldn't use two layout managers on one widget.
So use pack() OR grid() OR place().
You don't need pack() if you want to use grid() or place().
variable = Widget()
variable.grid()
or
variable = Widget()
variable.place(...)
or
variable = Widget()
variable.pack()
from tkinter import *
main = Tk()
name = Label(main,text="WELCOME TO \n AAROGYA SETU \n SELF EXAMINATION FRONT",font=("Bookman old style",30,'bold','italic'),bg="light blue").pack()
#linking sign up form
sign=Label(main,text="click button to sign up",font=("Bookman old style",20,"bold"),bg="light blue").pack()
main.mainloop()
this should work
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
How would you code a button, which changes its Image after you press it, but after 3 Seconds it changes Back to its normal state ?
I managed to change the Button Image with a Click, but the function sleep() stops the whole Tkinter Mainloop, which leads to the Button not doing anything.
As mentioned above, you need to make another function which changes the image back. You would then schedule that function to run later using the after method. This would be an ideal place to use a Button subclass to make a custom type of Button that incorporates those functions and the image data. Like this:
import tkinter as tk
class EleckTroniiKz(tk.Button):
"""A new type of Button that shows one image, changes to another image
when clicked, and changes back to the original image after 3 seconds"""
def __init__(self, master=None, image1=None, image2=None, **kwargs):
self.command = kwargs.pop('command', None)
super().__init__(master, **kwargs)
self.image1 = tk.PhotoImage(file=image1)
self.image2 = tk.PhotoImage(file=image2)
self.config(image=self.image1, command=self.on_click)
def on_click(self):
self.config(image=self.image2)
if self.command: self.command()
# schedule the after_click function to run 3 seconds from now
self.after(3000, self.after_click)
def after_click(self):
self.config(image=self.image1)
### test / demo
def main():
root = tk.Tk()
btn = EleckTroniiKz(root, 'OFF.gif', 'ON.gif')
btn.pack()
root.mainloop()
if __name__ == '__main__':
main()
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to know how to update the GUI at different time interval in QT, the best is that I could control the time intervals. I know QTimer could update GUI at the same time interval but I need to control the time intervals and set them to be different values.
Do I need to use multithreading?
I tried pyqt but Failed, please see "ui_mainwindow' object has no attribute 'connect'"
Here's how I would implement it, in your MainWindow's class, define a slot that sets the QLabel to the next image:
void MainWindow::NextImage(){
switch(currentImageNo){
case 0:
//set 1st image
break;
case 1:
//set 2nd image
break;
case 2:
//set 3rd image
break;
...
}
timer.setInterval( /*your desired new interval based on currentImageNo*/ );
currentImageNo++;
//in order to loop back to the first image after the last image is shown
currentImageNo= currentImageNo % numberOfImages;
}
in your MainWindow's constructor, create a QTimer with your desired interval and connect its timeout() signal to the NextImage slot defined above
MainWindow::MainWindow(){
...
timer= new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(NextImage()));
timer.setSingleShot(false);
timer.setInterval(5000); //5 secs for first image
timer.start();
NextImage(); //to load the first image initially
}
remember to declare and initialize currentImageNo, numberOfImages and timer as members of your MainWindow class.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i am going to have multiple questions so i figure i would put it into one thread so i do not flood the website with my stupid questions.
i will list all questions as an edited question, and hope it will be answered. the first question is as follows (on my 2nd question):
this is my first "real" graphics based game i will create, but i know i need assistance.
def update(self):
if games.keyboard.is_pressed(games.K_w):
self.y -= 1
if games.keyboard.is_pressed(games.K_a):
self.x -= 1
if games.keyboard.is_pressed(games.K_s):
self.y += 1
if games.keyboard.is_pressed(games.K_d):
self.x += 1
if games.keyboard.is_pressed(games.K_i):
Inventory()
the above is in my update function of my player class, checking to see if i is pressed.
def Inventory():
global LEVEL, TOTAL_XP, MAX_HEALTH, MAX_MAGICKA, viewing_inv
viewing_inv = True
inventory_items = []
while viewing_inv == True:
print "yo"
score = games.Text(value = "Points", size = 25, color = color.green, top = 5,
left = games.screen.width/2 + 14)
games.screen.add(score)
if games.keyboard.is_pressed(games.K_i):
games.screen.remove(score)
viewing_inv = False
the above is a temp inventory function i am using to make sure things are working, which they are not.
i added the print statement so i can view what is going on behind the scenes. i see the word "yo" print roughly 2-4 times each time i hit i. how can i successfully get it so that if i press i i go into the inventory function w/o having the computer loop through 2+ times before i can remove my finger? this question is already alot even though i want to be able to press i again to exit. any advice would be appreciated!
If your room class is working correctly you shouldn't need a global, think about using instance attributes which are set in the constructor.
Also I don't think a separate class per room type is needed. It feels unnecessarily complex, as essentially each room behaves the same - it may look different - but you can handle to look of the room via instance attributes. What you need I think is to create separate instances of the single room class, and when you create the instance, pass in the walls, enemies, floors etc.