Construct a horizontal LabeledScale with parent master, a variable to be associated with the Ttk Scale widget and its range. If variable is not specified, a tkinter.IntVar is created. WIDGET-SPECIFIC OPTIONS compound: 'top' or 'bottom' Spe
(self, master=None, variable=None, from_=0, to=10, **kw)
| 1483 | can be accessed through instance.label""" |
| 1484 | |
| 1485 | def __init__(self, master=None, variable=None, from_=0, to=10, **kw): |
| 1486 | """Construct a horizontal LabeledScale with parent master, a |
| 1487 | variable to be associated with the Ttk Scale widget and its range. |
| 1488 | If variable is not specified, a tkinter.IntVar is created. |
| 1489 | |
| 1490 | WIDGET-SPECIFIC OPTIONS |
| 1491 | |
| 1492 | compound: 'top' or 'bottom' |
| 1493 | Specifies how to display the label relative to the scale. |
| 1494 | Defaults to 'top'. |
| 1495 | """ |
| 1496 | self._label_top = kw.pop('compound', 'top') == 'top' |
| 1497 | |
| 1498 | Frame.__init__(self, master, **kw) |
| 1499 | self._variable = variable or tkinter.IntVar(master) |
| 1500 | self._variable.set(from_) |
| 1501 | self._last_valid = from_ |
| 1502 | |
| 1503 | self.label = Label(self) |
| 1504 | self.scale = Scale(self, variable=self._variable, from_=from_, to=to) |
| 1505 | self.scale.bind('<<RangeChanged>>', self._adjust) |
| 1506 | |
| 1507 | # position scale and label according to the compound option |
| 1508 | scale_side = 'bottom' if self._label_top else 'top' |
| 1509 | label_side = 'top' if scale_side == 'bottom' else 'bottom' |
| 1510 | self.scale.pack(side=scale_side, fill='x') |
| 1511 | # Dummy required to make frame correct height |
| 1512 | dummy = Label(self) |
| 1513 | dummy.pack(side=label_side) |
| 1514 | dummy.lower() |
| 1515 | self.label.place(anchor='n' if label_side == 'top' else 's') |
| 1516 | |
| 1517 | # update the label as scale or variable changes |
| 1518 | self.__tracecb = self._variable.trace_variable('w', self._adjust) |
| 1519 | self.bind('<Configure>', self._adjust) |
| 1520 | self.bind('<Map>', self._adjust) |
| 1521 | |
| 1522 | |
| 1523 | def destroy(self): |