I have added a button as:
def addButtons(self):
self.buttonBox = Pmw.ButtonBox(self.dataFrame,
labelpos = 'nw',
label_text = '',
frame_borderwidth = 1,
frame_relief = 'groove')
self.buttonBox.pack()
self.buttonBox.place(relx=.75, rely=.750, anchor=W)
# Add some buttons to the ButtonBox.
self.buttonBox.add('Login', command = self.login)
# Set the default button (the one executed when <Return> is hit).
self.buttonBox.setdefault('Login')
self.dataFrame.bind('<Return>', self._processReturnKey)
self.dataFrame.focus_set()
Now, I want to disable login button when user press it. How can i do that? I have found answer for simple button, but this button is in button box.
According to the pmw.ButtonBox documentation, the add method returns a reference to the button that is created. So, just save the reference that it returns and then configure that button like you would any other button.
Related
I have a ComboBox in TKinter from Which i can select an option from a drop down menu.
This works with either mouse click or ENTER key.
I want to do the same but with RIGHT key.
box1 = ttk.Combobox(root, values=different_values)
def boxenter():
#quasi ENTER key functionlity
box1.bind("<Right>",boxenter)
You need to bind on the Listbox widget created internally and this internal Listbox widget can be accessed by calling TCL command:
box1 = ttk.Combobox(root, values=different_values)
def boxenter(event):
# simulate "Enter" key
box1.event_generate('<Return>')
# get the popdown listbox created internally by TCL interpreter
popdown = box1.tk.eval(f'ttk::combobox::PopdownWindow {box1}') + '.f.l'
# call the undocumented _bind()
box1._bind(('bind', popdown), '<Right>', boxenter, None)
I have two buttons (Eg. A andB) which do the same things (based on user selection). So when you select something, then click the button, the selection's name will be input into the line-edit for the button. For example, if I click on buttonA, the input will be to lineEditA.
Currently I have created a signal function as follows:
def _connections_setup(self):
self.btnA.clicked.connect(self.get_sel_nameA)
self.btnB.clicked.connect(self.get_sel_nameB)
def get_sel_nameA(self):
sel_name = get_name_from_sel()
self.line_editA.setText(sel_name)
def get_sel_nameB(self):
sel_name = get_name_from_sel()
self.line_editA.setText(sel_name)
"""
def get_sel_name(self):
# Returns me a blank
button = self.sender()
print button.objectName()
# My objective here would be, if btnA is clicked, the sel_name will be inputted into lineEditA. Likewise for btnB
"""
Instead of creating two similar functions, how can I determine which button was clicked and have the selection's name to be input correctly into the line-edit?
I tried using self.sender() (see get_sel_name()) but it does not seems to return me the button name.
The sender() function only works in slots directly connected to signals. So your code needs to look something like this:
def _connections_setup(self):
self.btnA.clicked.connect(self.get_sel_name)
self.btnB.clicked.connect(self.get_sel_name)
def get_sel_name(self):
button = self.sender()
name = button.objectName()
if button is self.btnA:
self.line_editA.setText(name)
elif button is self.btnB:
self.line_editB.setText(name)
in maya one creates a button with:
cmds.button('buttonname', label='click me')
where buttonname is the name of
the button object. At a later stage i can edit the button simply by calling:
cmds.button('buttonname', e=1, label='click me again')
Now the problem:
i created a bunch of buttons in qt using a loop:
for s in Collection:
file = os.path.splitext(s)[0]
# Main widget
widgetItem = QtWidgets.QWidget()
layoutItem = QtWidgets.QVBoxLayout()
widgetItem.setLayout(layoutItem)
# Button
button = QtGui.QPushButton()
button.setObjectName(file)
layoutItem.addWidget(button)
How can i call/edit one of them using the button name?
Thanks in advance
Assuming you already have access to their parent widget, you can find them by findChild method.
In C++ syntax, it would be something like this:
QPushButton *button = parentWidget->findChild<QPushButton *>("button1");
where button1 is the name of that button.
I am working with buttons in Tkinter, Python.
The thing is when I click in one button the text of the button shakes. It might be a default behavior for this widget and I don't know how to disable it and make it static.
I assume that you mean the relief change from raised to sunken when you click a button.
This is what I found on http://wiki.tcl.tk/1048 (click 'Show Discussion' to see it):
Unfortunately, the relief used when you click is hardcoded (as
'sunken'), so you can't configure it per-widget without hacking the Tk
internals for the binding for buttons.
So the simplest way around this would be to always make the button appear sunken
MyButton = Tkinter.Button(
self.frame,
text = "Foobar",
command = self.foobar,
relief=Tkinter.SUNKEN
)
The disadvantage of that is that it might make the button look unresponsive.
You can also use a widget other than a button to be used as a clickable item (suggested by Joel Cornett). Here is a simple example with a label used as a button:
import Tkinter
class main:
def __init__(self,root):
# make a label with some space around the text
self.lbl1 = Tkinter.Label(root,
width = 16, height = 4,
text = "Foobar")
self.lbl1.pack()
# Call a function when lbl1 is clicked
# <Button-1> means a left mouse button click
self.lbl1.bind("<Button-1>", self.yadda)
self.lbl1.bind("<Enter>", self.green)
self.lbl1.bind("<Leave>", self.red)
def yadda(self, event):
self.lbl1.config(text="Clicked!")
def green(self, event):
self.lbl1.config(bg="green")
def red(self,event):
self.lbl1.config(bg="red")
if __name__ == "__main__":
root = Tkinter.Tk()
main(root)
root.mainloop()
I have a Tix.ComboBox with an editable text field. How do I force the variable holding the value for the text to update?
Let me give a more concrete explanation. I have a combo box and a button. When I click the button, it pops up a message box with the value of the combo box. Let's say the combo box text field currently has the value "thing1". If I type "new" into the box and then click on the button with my mouse, it will pops up the message "thing1". If I type "new" in the box and then tab focus away from the combo box and then click the button the pop up message says "new".
Ho do I force the combo box to update it's value to new without requiring that I tab away from the combo box?
I have included sample code.
import Tix
import tkMessageBox
class App(object):
def __init__(self, window):
window.winfo_toplevel().wm_title("test")
self.window = window
self.combo = Tix.ComboBox(window)
self.combo.insert(Tix.END, 'thing1')
self.combo.insert(Tix.END, 'thing2')
self.combo.entry['state'] = "normal"
self.combo['editable'] = True
self.combo.pack()
button = Tix.Button(window)
button['text'] = "Go"
button['command'] = self.go
button.pack()
def go(self):
tkMessageBox.showinfo('info', self.combo['value'])
if __name__ == '__main__':
root = Tix.Tk()
App(root)
root.mainloop()
woo!
solved it on my own.
Use
self.combo['selection']
instead of
self.combo['value']
NOTE: copy of Moe's answer that can be selected as chosen answer
woo!
solved it on my own.
Use
self.combo['selection']
instead of
self.combo['value']