Tkinter expand OptionMenu when focus is on it (Python 2.7) - configuration

I'm trying to create a GUI with an OptionMenu that can be used with only keyboard input.
When the user tabs to the OptionMenu (and puts the focus on it), I would like it to expand to show all the different options so that the user can select an option using the Up Arrow, Down Arrow and Return. Right now I can tab to the OptionMenu, but I have to click on it to reveal the different options.
Is there a way to automatically expand an OptionMenu when focus is on it? My current code:
self.status_options = ["", "Done", "In Progress"]
self.status_menu_var = StringVar(self)
self.status_menu_var.set(self.status_options[0])
self.status_menu = apply(OptionMenu, (self, self.status_menu_var) + tuple(self.status_options))
self.status_menu.configure(takefocus=1) #Allow user to tab over option menu
self.status_menu.grid(column = 1, row = 6, sticky = "EW")

Related

Set state togglebutton with databinding

I've got a form that contains a toggle button. To set the state of the togglebutton I use the property 'ToggleState' (which can be true or false).
I want to set the toggle button via databinding. I've pulled some data from a database and placed this in a listbox.
When selecting a item from the listbox all the other fields are populated with the corresponding data.
The only thing that's not set correctly is the toggle button.
Here is the code I have used to set the buttonstate via databinding. The buttonstate does not work.
ToggleButton1.DataBindings.Add("ToggleState", table, "Goedgekeurd", True, DataSourceUpdateMode.OnPropertyChanged)
If I use the code below the buttonstate will set correctly.
ToggleButton1.ToggleState = 1
Can someone help me out what the difference is between the two?

Toggling the Caption on a continuous Form

On a continuous form I am attempting to toggle the caption of a toggle button to match the button’s state. In this case when the record/state is True, I would like the button to read “Current” and if the record is False have the button read “Obsolete”.
The script below works in switching between the two desired values but is switches all of the visible buttons and not for the individual records. I am not sure how to tie the individual records to the individual togglebutton's caption.
Private Sub Toggle5_Click()
If Me.Toggle5.Value = True Then
Me.Toggle5.Caption = "Current"
Else:
Me.Toggle5.Caption = "Obsolete"
End If
End Sub
I am using MS- Access 2013, I expect this question has been answer before, I have not found a working solution.
As Gustav wrote, you cannot do this directly. All static properties of controls in a continuous form always apply to all instances of that control.
Possible workaround:
Use a textbox (disabled & locked, perhaps with special effect = Raised) to show the text, with a control source like this:
= IIf([Status]=True, "Current", "Obsolete")
Put a transparent button on top of it, for easy clickability (it won't show a Click animation though).
Use Conditional formatting to set the background color of the textbox.
You can't.
An unbound control in a continuous form carries the same values and properties on all records.

Continous Form - Image control click event to recognise current record

I have a subform that looks like this that I'm wanting to use as a task list:
The task is marked as completed in the record using a Yes/No field called TaskStatus; this is shown as the checkbox control to the right in the above screenshot.
Rather than use this checkbox though, I'd like to do something a bit more fancy-pants and have the user click the image control called imgTaskIcon shown as the red flag on the left, which will both mark the TaskStatus field for the record appropriately and toggle its own image to that of either a red flag (not completed) or a green tick (completed).
At the moment, I have the control source of imgTaskIcon set to look at another (hidden) field in the record that is storing the path to the appropriate completed/not completed image.
I've then got this code running on imgTaskIcon click event, which essentially toggles TaskStatus from yes (-1) to no (0):
Private Sub imgTaskIcon_Click()
If _
Me.TaskStatus = -1 _
Then
Me.TaskStatus = 0
Else
Me.TaskStatus = -1
End If
toggleTaskStatusIcon
End Sub
And then toggleTaskStatusIcon, which sets the correct image path for the record:
Public Sub toggleTaskStatusIcon()
If _
Me.TaskStatus = -1 _
Then
Me.TaskStatusIcon = "P:\myPath\CompletedIcon.png"
Else
Me.TaskStatusIcon = "P:\myPath\NotCompletedIcon.png"
End If
End Sub
This works fine when toggling the first record:
However, clicking the image on the second record, just toggles the first record again:
By first clicking in to some other control in the record, I can then click the image control and the toggle works on the appropriate record. So it seems that an image control won't change the current record to its own record when it is clicked.
Is there a way to get an image control to be less ambivalent about where it lives?

tap event: how to set an event for first tap, and another event for second tap

I'm developing a Windows phone 8 app with visual studio.
I made two buttons, button1 and button2, and two textblocks that are under each button.
Button2 is under the button1, so button2 and textblock1 are overlaying each other.
When user clicks button1 I set textblock1.Visibility = true, and change button2's margin, so the app renders the following layout:
In the upper part there is the button1.
The textblock1 is in the middle
And the button2 is in the lowest part.
Now, when I re-tap the button1 I just want that textblock1.Visibility turns false and button2 returns to is original position. So I want to implement a species of dropdown button text, but i haven't find a way to do that.
Can anyone help me? Is there another way to to that?
I've tried a Listpicker from WPToolkit, but I don't want the selected item to be shown in the listpicker when this is not selected, and substantially I have the same tap problem.
I'm going to answer to the question that is in your thread title : "tap event: how to set an event for first tap, and another event for second tap".
There is several ways, you can set up a boolean variable or increase a counter.
In your case, you can check the visibility of your textblock1 :
if(textblock1.Visibility == Visibility.Collapsed)
{
//first click
textblock1.Visibility = Visibility.Visible;
}
else {
//second click
textblock1.Visibility = Visibility.Collapsed;
}
To the previous code you just have to add your instructions for the button2 position.
If you want to create your own ListPicker or ComboBox, you can read this tutorial but it is in french... :)

Create a Tab (call it MNOP) with a layout that contains textboxes that take data(numbers).

How do I create a tab in a PyQT UI that has a layout that contains the following, example.
tab name-MNOP
Layout has.
a1: textbox that can input data (numbers)
a2: textbox hat can input data
a3: textbox that can input data
a4: textbox that can input data
the data input will be stored in the db and used to create bar-graphs. right now I need to create the tab and textboxes.
right now, I am working with the following-incomplete but don't know how to proceed.
class RPBDlg(QDialog):
def __init__(self, parent=None):
super(RPBDlg, self).__init__(parent)
self.newcounter =0
grid = QGridLayout()
label = QLabel()
label.setText("<B>Plan Title:</B>")
self.titleEdit = QLineEdit()
grid.addWidget(label,0,0,1,1)
grid.addWidget(self.titleEdit,0,1,1,1)
label2 = QLabel("<B>Type of Plan</B>")
self.typeEdit = QComboBox()
self.typeEdit.addItems(["STI","LTI","STI and LTI"])
grid.addWidget(label2,1,0,1,1)
grid.addWidget(self.typeEdit,1,1,1,1)
self.bonusPool = QCheckBox("Bonus Pool")
grid.addWidget(self.bonusPool,1,4,1,1)
label3 = QLabel("<B>Sub-Type of Plan<B>")
self.subTypeEdit = QComboBox()
self.subTypeEdit.addItems(["Regular","Profit Sharing","Multiplier Based"])
grid.addWidget(label3,1,2,1,1)
grid.addWidget(self.subTypeEdit,1,3,1,1)
self.label4 = QLabel("<B>Are individual awards determined <br>through a performance formula?")
self.bonusPoolAdditional = QComboBox()
self.bonusPoolAdditional.addItems(["Yes - separate formula for individual awards","Yes - individual awards are proportional to bonus pool", "No - individual awards are discretionary","No - individual awards determined through negative discretion"])
grid.addWidget(self.label4,3,0,1,1)
grid.addWidget(self.bonusPoolAdditional,3,1,1,2)
Imports are present. This code is part of a much larger code.
If you want to use tabs in your UI you should create a QTabWidget. The basic steps for working with it are:
create a QTabWidget.
Create a QWidget with no parent for each of the pages in the tab dialog.
for them.
Insert child widgets into the page widget, using layouts to position them as normal.
Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.
You can find detailed information in the documentation page of the widget.