I need some help with the led option 'on_click_callback=' of the led widget in the module tk_tools.py. Here's what I have:
reactor_led = Led(win, size=50, toggle_on_click=True, on_click_callback=led_clicked(ON))
reactor_led.to_red()
reactor_led.to_green(on=True)
reactor_led.grid()
The led does get displayed properly in its window, and it does react correctly to a mouse click. I've omitted the code for led_clicked, but it is being called when I click the 'led'. The parameter "ON" is the boolean state of the led when clicked, but I can't come up with the actual code to reference that to pass to the call-back function. I need a working example to understand it.
Thanks
Related
I want to use KivyMDs FloatingActionButtonSpeedDial, with something different happening depending on which stack button is pressed. Right now, I'm just trying to print which button was pressed.
I've found outdated information from tutorials, but it looks like the current way to set a function on the button press is:
on_press_stack_button: root.callback(self)
then in my .py file I have
def callback(self, instance):
print(instance.icon)
but no matter which stack icon I choose, the result that's printed is always 'plus' (the root icon)
I'm guessing this is because I'm passing self into the callback function, but what else am I supposed to pass to access the actual button that's clicked? I can't find any examples in the docs, and all the tutorials I find say to use
'''
callback: callback
'''
instead of on_press_stack_button:
but using callback doesn't print anything at all.
Any help is greatly appreciated!
In my experimenting I have found that in some cases the graphical check display can be changed without stateChanged being sent, but clicked appears to always go. What is the difference?
In particular, something like this:
checkBox.stateChanged.connect(func)
def func(state):
print "Not allowed!"
checkBox.setChecked(not bool(state))
Does not work with stateChanged. It appears to get into func every other time only. What is going on? If I replace stateChanged with clicked, it works as expected.
Don't forget that you can change checkbox state programmatically. checkbox.setChecked(True) will emit stateChanged but not clicked
I am trying to write my 1St Maya Python Script......I know I have a ways to go before I don't keep getting dozens of Syntax Errors....But it's a simple script with no UI, and any even tidbits or clues I can get to get it to work will set me off with scripting.
Just a simple fuction of 'Clicking and dragging' visibilities on or off of the Display Layer boxes..the main function I am trying to define is:
draggerContext?
or
cmds.selectPref(clickBoxSize=True)
how to implement the fuction on/off..
any clues would be of help as the trickiest part of this script is defining the Function of CLick Drag select...
Thanks
my script that does not work yet:
import maya.cmds as cmds
#Click and drag to Turn On/Off Visibilities of the Display Layers
draggerContext_id = "dga"
def dga():
cmds.selectPref(clickBoxSize=True)
cmds.selectcmds.selectPref(clickBoxSize=True)
if:
clickdragBoxSize.sel=True(layerEditorLayerButtonVisibilityChange):
cmds.selectPref(clickBoxSize=True)
else:
cmds.select(layerEditorLayerButtonVisibilityChange=True)
SelectLayerEditorButtonVisibility()
So I have this very simple thing I wrote and it's killing me trying to figure out why it won't work. All it does it print a statement when you click.
So for the first example I had a button and assigned the function printName1 directly to it, which worked perfectly fine.
Then the next thing was to bind it using the .bind() function. So in this case we just have a frame that prints out certain things based on which button you press. But unfortunately whenever I use bind, it throws the error show above. References tkinter\__init__.py for the error, so it's not something directly in my code but maybe it needs to be done differently? Thanks guys.
from tkinter import *
root = Tk()
def printName1():
print('Jack')
def printName2():
print('John')
def printName3():
print('Jill')
frame = Frame(root, width=300, height=250)
frame.bind("<Button-1>", printName1)
frame.bind("<Button-2>", printName2)
frame.bind("<Button-3>", printName3)
frame.pack()
root.mainloop()
EDIT: The error is confusing because it made it seem like there was an extra argument when there should be 0. But actually I needed to add an argument to the functions and that was event. so it should be def printName1(event) and so on. Just figured I would let you guys know what worked for me in case anyone stumbles upon this.
If you refer to the documentation regarding tkinter events and bindings, you will see that when an event is triggered, the associated event object will be passed as the first (and only) argument to the bounded function (being printName1 and friends in your case).
So what you need to do is to modify those printName* functions to accept the event argument.
def printName1(event):
print('Jack')
Then what you desired to achieve should work.
Naturally, you could make the event argument optional as #TigerhawkT3 suggested.
Events, such as from the keyboard/mouse, are all sent to the application with information about the event: which key was it, where was the mouse when you clicked, that sort of thing. This means that any callback bound to such an event needs to take an argument. If you want to also bind it to a Tkinter Button, which doesn't take an event, you can handle that as well. Just define your functions with a default argument:
def printName1(event=None):
...
I'm working on a bold button for a text editor. I'm having trouble with setting the button "sunken" when bold text is selected.
I imagine it will be something like the below?
self.textPad.tag_bind("bt","<Button-1>",self.boldP())
def boldP(self):
self.boldB.config(relief="sunken")
Not sure if I got the right idea, could someone please shed some light on this for me?
I'm not sure it's the main problem, but one problem with the code snippet that you posted is that you are not actually giving a callback to tag_bind, you are giving it None. Why? Because you are calling boldP, which returns None. Change this line:
self.textPad.tag_bind("bt","<Button-1>",self.boldP())
To:
self.textPad.tag_bind("bt", "<Button-1>", self.boldP)
Another problem is that your callback should take an event argument:
def boldP(self, event):
...
I'm not too familiar with Tkinter, so I'm not so sure about how tag_bind is supposed to work - but it seems like it's mostly used with canvas objects. Is this what you are doing? Otherwise try bind. Something like this:
self.button.bind(,"<Button-1>", self.boldP)