跳转至

Querybox

Static methods that request data from the end user.

Source code in src/ttkbootstrap/dialogs/query.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
class Querybox:
    """Static methods that request data from the end user."""

    @staticmethod
    def get_color(
            parent: Optional[tkinter.Misc] = None,
            title: str = "Color Chooser",
            initialcolor: Optional[str] = None,
            **kwargs: Any,
    ) -> Any:
        """Show a color picker and return the selected color when OK is pressed."""
        from ttkbootstrap.dialogs.colorchooser import ColorChooserDialog

        dialog = ColorChooserDialog(parent, title, initialcolor)
        position = kwargs.pop("position", None)
        dialog.show(position)
        return dialog.result

    @staticmethod
    def get_date(
            parent: Optional[tkinter.Misc] = None,
            title: str = " ",
            firstweekday: int = 6,
            startdate: Optional[date] = None,
            bootstyle: str = "primary",
    ) -> date:
        chooser = DatePickerDialog(
            parent=parent,
            title=title,
            firstweekday=firstweekday,
            startdate=startdate,
            bootstyle=bootstyle,
        )
        return chooser.date_selected

    @staticmethod
    def get_string(
            prompt: str = "",
            title: str = " ",
            initialvalue: Optional[str] = None,
            parent: Optional[tkinter.Misc] = None,
            **kwargs: Any,
    ) -> Optional[str]:
        initialvalue = initialvalue or ""
        position = kwargs.pop("position", None)
        dialog = QueryDialog(prompt, title, initialvalue, parent=parent, **kwargs)
        dialog.show(position)
        return dialog._result

    @staticmethod
    def get_item(
            prompt: str = "",
            title: str = " ",
            initialvalue: Optional[str] = None,
            items: Optional[List[str]] = None,
            parent: Optional[tkinter.Misc] = None,
            **kwargs: Any,
    ) -> Optional[str]:
        initialvalue = initialvalue or ""
        position = kwargs.pop("position", None)
        dialog = QueryDialog(prompt, title, initialvalue, items=items, parent=parent, **kwargs)
        dialog.show(position)
        return dialog._result

    @staticmethod
    def get_integer(
            prompt: str = "",
            title: str = " ",
            initialvalue: Optional[int] = None,
            minvalue: Optional[int] = None,
            maxvalue: Optional[int] = None,
            parent: Optional[tkinter.Misc] = None,
            **kwargs: Any,
    ) -> Optional[int]:
        initialvalue = initialvalue or ""
        position = kwargs.pop("position", None)
        dialog = QueryDialog(
            prompt,
            title,
            initialvalue,
            minvalue,
            maxvalue,
            datatype=int,
            parent=parent,
            **kwargs,
        )
        dialog.show(position)
        return dialog._result

    @staticmethod
    def get_float(
            prompt: str = "",
            title: str = " ",
            initialvalue: Optional[float] = None,
            minvalue: Optional[float] = None,
            maxvalue: Optional[float] = None,
            parent: Optional[tkinter.Misc] = None,
            **kwargs: Any,
    ) -> Optional[float]:
        initialvalue = initialvalue or ""
        position = kwargs.pop("position", None)
        dialog = QueryDialog(
            prompt,
            title,
            initialvalue,
            minvalue,
            maxvalue,
            datatype=float,
            parent=parent,
            **kwargs,
        )
        dialog.show(position)
        return dialog._result

    @staticmethod
    def get_font(parent: Optional[tkinter.Misc] = None, **kwargs: Any):
        position = kwargs.pop("position", None)
        dialog = FontDialog(parent=parent, **kwargs)
        dialog.show(position)
        return dialog.result

get_color(parent=None, title='Color Chooser', initialcolor=None, **kwargs) staticmethod

Show a color picker and return the selected color when OK is pressed.

Source code in src/ttkbootstrap/dialogs/query.py
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@staticmethod
def get_color(
        parent: Optional[tkinter.Misc] = None,
        title: str = "Color Chooser",
        initialcolor: Optional[str] = None,
        **kwargs: Any,
) -> Any:
    """Show a color picker and return the selected color when OK is pressed."""
    from ttkbootstrap.dialogs.colorchooser import ColorChooserDialog

    dialog = ColorChooserDialog(parent, title, initialcolor)
    position = kwargs.pop("position", None)
    dialog.show(position)
    return dialog.result