1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
from tkinter import Frame
from . import utilities as utils
from .base import ContainerWidget
class Box(ContainerWidget):
def __init__(
self,
master,
layout="auto",
grid=None,
align=None,
visible=True,
enabled=None,
width=None,
height=None,
border=None):
"""
Creates a Box
:param Container master:
The Container (App, Box, etc) the Box will belong too.
:param string layout:
The layout the Box should use "auto" or "grid. Defaults to "auto".
:param List grid:
Grid co-ordinates for the widget, required if the master layout
is 'grid', defaults to `None`.
:param string align:
How to align the widget within the grid, defaults to `None`.
:param callback args:
A list of arguments to pass to the widgets `command`, defaults to
`None`.
:param bool visible:
If the widget should be visible, defaults to `True`.
:param bool enabled:
If the widget should be enabled, defaults to `None`. If `None`
the value is inherited from the master.
:param int width:
The starting width of the widget. Defaults to `None` and will auto
size. If not `None`, both the width and height need to be set.
:param int height:
The starting height of the widget. Defaults to `None` and will auto
size. If not `None`, both the width and height need to be set.
:param int border:
Sets the border thickness. `0` or `False` is no border. `True` or
value > 1 sets a border. The default is `None`.
"""
self._grid = grid
self._align = align
description = "[Box] object (may also contain other objects)"
tk = Frame(master.tk)
super(Box, self).__init__(master, tk, description, layout, grid, align, visible, enabled, width, height)
self.resize(width, height)
if border is not None:
self.border = border
@property
def border(self):
"""
Sets or returns the border thickness.
`0` or `False` is no border.
`True` or value > 1 sets a border
"""
return self._get_tk_config("highlightthickness")
@border.setter
def border(self, value):
self.set_border(value, "black")
def set_border(self, thickness, color="black"):
"""
Sets the border thickness and color.
:param int thickness:
The thickenss of the border.
:param str color:
The color of the border.
"""
self._set_tk_config("highlightthickness", thickness)
self._set_tk_config("highlightbackground", utils.convert_color(color))
def resize(self, width, height):
"""
Resizes the widget.
:param int width:
The width of the widget.
:param int height:
The height of the widget.
"""
self._set_propagation(width, height)
super(Box, self).resize(width, height)
|