当前位置:   article > 正文

ttkbootstrap界面美化系列之Meter(六)_ttkbootstrap meter

ttkbootstrap meter

        Meter是计量表控件,在大数据统计类的界面设计中使用较多,本文将介绍ttk中的Meter控件

一:Meter接口

print(help(ttk.Meter))
  1. Help on class Meter in module ttkbootstrap.widgets:
  2. class Meter(tkinter.ttk.Frame)
  3. | Meter(master=None, bootstyle='default', arcrange=None, arcoffset=None, amounttotal=100, amountused=0, wedgesize=0, metersize=200, metertype='full', meterthickness=10, showtext=True, interactive=False, stripethickness=0, textleft=None, textright=None, textfont='-size 20 -weight bold', subtext=None, subtextstyle='default', subtextfont='-size 10', stepsize=1, **kwargs)
  4. |
  5. | A radial meter that can be used to show progress of long
  6. | running operations or the amount of work completed; can also be
  7. | used as a dial when set to `interactive=True`.
  8. |
  9. | This widget is very flexible. There are two primary meter types
  10. | which can be set with the `metertype` parameter: 'full' and
  11. | 'semi', which shows the arc of the meter in a full or
  12. | semi-circle. You can also customize the arc of the circle with
  13. | the `arcrange` and `arcoffset` parameters.
  14. |
  15. | The meter indicator can be displayed as a solid color or with
  16. | stripes using the `stripethickness` parameter. By default, the
  17. | `stripethickness` is 0, which results in a solid meter
  18. | indicator. A higher `stripethickness` results in larger wedges
  19. | around the arc of the meter.
  20. |
  21. | Various text and label options exist. The center text and
  22. | meter indicator is formatted with the `meterstyle` parameter.
  23. | You can set text on the left and right of this center label
  24. | using the `textleft` and `textright` parameters. This is most
  25. | commonly used for '$', '%', or other such symbols.
  26. |
  27. | If you need access to the variables that update the meter, you
  28. | you can access these via the `amountusedvar`, `amounttotalvar`,
  29. | and the `labelvar`. The value of these properties can also be
  30. | retrieved via the `configure` method.
  31. |
  32. | ![](../../assets/widgets/meter.gif)
  33. |
  34. | Examples:
  35. |
  36. | ```python
  37. | import ttkbootstrap as ttk
  38. | from ttkbootstrap.constants import *
  39. |
  40. | app = ttk.Window()
  41. |
  42. | meter = ttk.Meter(
  43. | metersize=180,
  44. | padding=5,
  45. | amountused=25,
  46. | metertype="semi",
  47. | subtext="miles per hour",
  48. | interactive=True,
  49. | )
  50. | meter.pack()
  51. |
  52. | # update the amount used directly
  53. | meter.configure(amountused = 50)
  54. |
  55. | # update the amount used with another widget
  56. | entry = ttk.Entry(textvariable=meter.amountusedvar)
  57. | entry.pack(fill=X)
  58. |
  59. | # increment the amount by 10 steps
  60. | meter.step(10)
  61. |
  62. | # decrement the amount by 15 steps
  63. | meter.step(-15)
  64. |
  65. | # update the subtext
  66. | meter.configure(subtext="loading...")
  67. |
  68. | app.mainloop()
  69. | ```
  70. |
  71. | Method resolution order:
  72. | Meter
  73. | tkinter.ttk.Frame
  74. | tkinter.ttk.Widget
  75. | tkinter.Widget
  76. | tkinter.BaseWidget
  77. | tkinter.Misc
  78. | tkinter.Pack
  79. | tkinter.Place
  80. | tkinter.Grid
  81. | builtins.object
  82. |
  83. | Methods defined here:
  84. |
  85. | __getitem__(self, key: str)
  86. | Return the resource value for a KEY given as string.
  87. |
  88. | __init__(self, master=None, bootstyle='default', arcrange=None, arcoffset=None, amounttotal=100, amountused=0, wedgesize=0, metersize=200, metertype='full', meterthickness=10, showtext=True, interactive=False, stripethickness=0, textleft=None, textright=None, textfont='-size 20 -weight bold', subtext=None, subtextstyle='default', subtextfont='-size 10', stepsize=1, **kwargs)
  89. | Parameters:
  90. |
  91. | master (Widget):
  92. | The parent widget.
  93. |
  94. | arcrange (int):
  95. | The range of the arc if degrees from start to end.
  96. |
  97. | arcoffset (int):
  98. | The amount to offset the arc's starting position in degrees.
  99. | 0 is at 3 o'clock.
  100. |
  101. | amounttotal (int):
  102. | The maximum value of the meter.
  103. |
  104. | amountused (int):
  105. | The current value of the meter; displayed in a center label
  106. | if the `showtext` property is set to True.
  107. |
  108. | wedgesize (int):
  109. | Sets the length of the indicator wedge around the arc. If
  110. | greater than 0, this wedge is set as an indicator centered
  111. | on the current meter value.
  112. |
  113. | metersize (int):
  114. | The meter is square. This represents the size of one side
  115. | if the square as measured in screen units.
  116. |
  117. | bootstyle (str):
  118. | Sets the indicator and center text color. One of primary,
  119. | secondary, success, info, warning, danger, light, dark.
  120. |
  121. | metertype ('full', 'semi'):
  122. | Displays the meter as a full circle or semi-circle.
  123. |
  124. | meterthickness (int):
  125. | The thickness of the indicator.
  126. |
  127. | showtext (bool):
  128. | Indicates whether to show the left, center, and right text
  129. | labels on the meter.
  130. |
  131. | interactive (bool):
  132. | Indicates that the user may adjust the meter value with
  133. | mouse interaction.
  134. |
  135. | stripethickness (int):
  136. | The indicator can be displayed as a solid band or as
  137. | striped wedges around the arc. If the value is greater than
  138. | 0, the indicator changes from a solid to striped, where the
  139. | value is the thickness of the stripes (or wedges).
  140. |
  141. | textleft (str):
  142. | A short string inserted to the left of the center text.
  143. |
  144. | textright (str):
  145. | A short string inserted to the right of the center text.
  146. |
  147. | textfont (Union[str, Font]):
  148. | The font used to render the center text.
  149. |
  150. | subtext (str):
  151. | Supplemental text that appears below the center text.
  152. |
  153. | subtextstyle (str):
  154. | The bootstyle color of the subtext. One of primary,
  155. | secondary, success, info, warning, danger, light, dark.
  156. | The default color is Theme specific and is a lighter
  157. | shade based on whether it is a 'light' or 'dark' theme.
  158. |
  159. | subtextfont (Union[str, Font]):
  160. | The font used to render the subtext.
  161. |
  162. | stepsize (int):
  163. | Sets the amount by which to change the meter indicator
  164. | when incremented by mouse interaction.
  165. |
  166. | **kwargs:
  167. | Other keyword arguments that are passed directly to the
  168. | `Frame` widget that contains the meter components.
  169. |
  170. | __setitem__(self, key: str, value) -> None
  171. |
  172. | configure(self, cnf=None, **kwargs)
  173. | Configure the options for this widget.
  174. |
  175. | Parameters:
  176. | cnf (Dict[str, Any], optional):
  177. | A dictionary of configuration options.
  178. |
  179. | **kwargs: Optional keyword arguments.
  180. |
  181. | step(self, delta=1)
  182. | Increase the indicator value by `delta`
  183. |
  184. | The indicator will reverse direction and count down once it
  185. | reaches the maximum value.
  186. |
  187. | Parameters:
  188. |
  189. | delta (int):
  190. | The amount to change the indicator.
  191. |
  192. | ----------------------------------------------------------------------
  193. | Methods inherited from tkinter.ttk.Frame:
  194. |
  195. | config = configure(self, cnf=None, **kwargs)
  196. |
  197. | ----------------------------------------------------------------------
  198. | Methods inherited from tkinter.ttk.Widget:
  199. |
  200. | identify(self, x, y)
  201. | Returns the name of the element at position x, y, or the empty
  202. | string if the point does not lie within any element.
  203. |
  204. | x and y are pixel coordinates relative to the widget.
  205. |
  206. | instate(self, statespec, callback=None, *args, **kw)
  207. | Test the widget's state.
  208. |
  209. | If callback is not specified, returns True if the widget state
  210. | matches statespec and False otherwise. If callback is specified,
  211. | then it will be invoked with *args, **kw if the widget state
  212. | matches statespec. statespec is expected to be a sequence.
  213. |
  214. | state(self, statespec=None)
  215. | Modify or inquire widget state.
  216. |
  217. | Widget state is returned if statespec is None, otherwise it is
  218. | set according to the statespec flags and then a new state spec
  219. | is returned indicating which flags were changed. statespec is
  220. | expected to be a sequence.
  221. |
  222. | ----------------------------------------------------------------------
  223. | Methods inherited from tkinter.BaseWidget:
  224. |
  225. | destroy(self)
  226. | Destroy this and all descendants widgets.
  227. |
  228. | ----------------------------------------------------------------------
  229. | Methods inherited from tkinter.Misc:
  230. |
  231. | __repr__(self)
  232. | Return repr(self).
  233. |
  234. | __str__(self)
  235. | Return the window path name of this widget.
  236. |
  237. | after(self, ms, func=None, *args)
  238. | Call function once after given time.
  239. |
  240. | MS specifies the time in milliseconds. FUNC gives the
  241. | function which shall be called. Additional parameters
  242. | are given as parameters to the function call. Return
  243. | identifier to cancel scheduling with after_cancel.
  244. |
  245. | after_cancel(self, id)
  246. | Cancel scheduling of function identified with ID.
  247. |
  248. | Identifier returned by after or after_idle must be
  249. | given as first parameter.
  250. |
  251. | after_idle(self, func, *args)
  252. | Call FUNC once if the Tcl main loop has no event to
  253. | process.
  254. |
  255. | Return an identifier to cancel the scheduling with
  256. | after_cancel.
  257. |
  258. | anchor = grid_anchor(self, anchor=None)
  259. |
  260. | bbox = grid_bbox(self, column=None, row=None, col2=None, row2=None)
  261. |
  262. | bell(self, displayof=0)
  263. | Ring a display's bell.
  264. |
  265. | bind(self, sequence=None, func=None, add=None)
  266. | Bind to this widget at event SEQUENCE a call to function FUNC.
  267. |
  268. | SEQUENCE is a string of concatenated event
  269. | patterns. An event pattern is of the form
  270. | <MODIFIER-MODIFIER-TYPE-DETAIL> where MODIFIER is one
  271. | of Control, Mod2, M2, Shift, Mod3, M3, Lock, Mod4, M4,
  272. | Button1, B1, Mod5, M5 Button2, B2, Meta, M, Button3,
  273. | B3, Alt, Button4, B4, Double, Button5, B5 Triple,
  274. | Mod1, M1. TYPE is one of Activate, Enter, Map,
  275. | ButtonPress, Button, Expose, Motion, ButtonRelease
  276. | FocusIn, MouseWheel, Circulate, FocusOut, Property,
  277. | Colormap, Gravity Reparent, Configure, KeyPress, Key,
  278. | Unmap, Deactivate, KeyRelease Visibility, Destroy,
  279. | Leave and DETAIL is the button number for ButtonPress,
  280. | ButtonRelease and DETAIL is the Keysym for KeyPress and
  281. | KeyRelease. Examples are
  282. | <Control-Button-1> for pressing Control and mouse button 1 or
  283. | <Alt-A> for pressing A and the Alt key (KeyPress can be omitted).
  284. | An event pattern can also be a virtual event of the form
  285. | <<AString>> where AString can be arbitrary. This
  286. | event can be generated by event_generate.
  287. | If events are concatenated they must appear shortly
  288. | after each other.
  289. |
  290. | FUNC will be called if the event sequence occurs with an
  291. | instance of Event as argument. If the return value of FUNC is
  292. | "break" no further bound function is invoked.
  293. |
  294. | An additional boolean parameter ADD specifies whether FUNC will
  295. | be called additionally to the other bound function or whether
  296. | it will replace the previous function.
  297. |
  298. | Bind will return an identifier to allow deletion of the bound function with
  299. | unbind without memory leak.
  300. |
  301. | If FUNC or SEQUENCE is omitted the bound function or list
  302. | of bound events are returned.
  303. |
  304. | bind_all(self, sequence=None, func=None, add=None)
  305. | Bind to all widgets at an event SEQUENCE a call to function FUNC.
  306. | An additional boolean parameter ADD specifies whether FUNC will
  307. | be called additionally to the other bound function or whether
  308. | it will replace the previous function. See bind for the return value.
  309. |
  310. | bind_class(self, className, sequence=None, func=None, add=None)
  311. | Bind to widgets with bindtag CLASSNAME at event
  312. | SEQUENCE a call of function FUNC. An additional
  313. | boolean parameter ADD specifies whether FUNC will be
  314. | called additionally to the other bound function or
  315. | whether it will replace the previous function. See bind for
  316. | the return value.
  317. |
  318. | bindtags(self, tagList=None)
  319. | Set or get the list of bindtags for this widget.
  320. |
  321. | With no argument return the list of all bindtags associated with
  322. | this widget. With a list of strings as argument the bindtags are
  323. | set to this list. The bindtags determine in which order events are
  324. | processed (see bind).
  325. |
  326. | cget(self, key)
  327. | Return the resource value for a KEY given as string.
  328. |
  329. | clipboard_append(self, string, **kw)
  330. | Append STRING to the Tk clipboard.
  331. |
  332. | A widget specified at the optional displayof keyword
  333. | argument specifies the target display. The clipboard
  334. | can be retrieved with selection_get.
  335. |
  336. | clipboard_clear(self, **kw)
  337. | Clear the data in the Tk clipboard.
  338. |
  339. | A widget specified for the optional displayof keyword
  340. | argument specifies the target display.
  341. |
  342. | clipboard_get(self, **kw)
  343. | Retrieve data from the clipboard on window's display.
  344. |
  345. | The window keyword defaults to the root window of the Tkinter
  346. | application.
  347. |
  348. | The type keyword specifies the form in which the data is
  349. | to be returned and should be an atom name such as STRING
  350. | or FILE_NAME. Type defaults to STRING, except on X11, where the default
  351. | is to try UTF8_STRING and fall back to STRING.
  352. |
  353. | This command is equivalent to:
  354. |
  355. | selection_get(CLIPBOARD)
  356. |
  357. | columnconfigure = grid_columnconfigure(self, index, cnf={}, **kw)
  358. |
  359. | deletecommand(self, name)
  360. | Internal function.
  361. |
  362. | Delete the Tcl command provided in NAME.
  363. |
  364. | event_add(self, virtual, *sequences)
  365. | Bind a virtual event VIRTUAL (of the form <<Name>>)
  366. | to an event SEQUENCE such that the virtual event is triggered
  367. | whenever SEQUENCE occurs.
  368. |
  369. | event_delete(self, virtual, *sequences)
  370. | Unbind a virtual event VIRTUAL from SEQUENCE.
  371. |
  372. | event_generate(self, sequence, **kw)
  373. | Generate an event SEQUENCE. Additional
  374. | keyword arguments specify parameter of the event
  375. | (e.g. x, y, rootx, rooty).
  376. |
  377. | event_info(self, virtual=None)
  378. | Return a list of all virtual events or the information
  379. | about the SEQUENCE bound to the virtual event VIRTUAL.
  380. |
  381. | focus = focus_set(self)
  382. |
  383. | focus_displayof(self)
  384. | Return the widget which has currently the focus on the
  385. | display where this widget is located.
  386. |
  387. | Return None if the application does not have the focus.
  388. |
  389. | focus_force(self)
  390. | Direct input focus to this widget even if the
  391. | application does not have the focus. Use with
  392. | caution!
  393. |
  394. | focus_get(self)
  395. | Return the widget which has currently the focus in the
  396. | application.
  397. |
  398. | Use focus_displayof to allow working with several
  399. | displays. Return None if application does not have
  400. | the focus.
  401. |
  402. | focus_lastfor(self)
  403. | Return the widget which would have the focus if top level
  404. | for this widget gets the focus from the window manager.
  405. |
  406. | focus_set(self)
  407. | Direct input focus to this widget.
  408. |
  409. | If the application currently does not have the focus
  410. | this widget will get the focus if the application gets
  411. | the focus through the window manager.
  412. |
  413. | getboolean(self, s)
  414. | Return a boolean value for Tcl boolean values true and false given as parameter.
  415. |
  416. | getdouble(self, s)
  417. |
  418. | getint(self, s)
  419. |
  420. | getvar(self, name='PY_VAR')
  421. | Return value of Tcl variable NAME.
  422. |
  423. | grab_current(self)
  424. | Return widget which has currently the grab in this application
  425. | or None.
  426. |
  427. | grab_release(self)
  428. | Release grab for this widget if currently set.
  429. |
  430. | grab_set(self)
  431. | Set grab for this widget.
  432. |
  433. | A grab directs all events to this and descendant
  434. | widgets in the application.
  435. |
  436. | grab_set_global(self)
  437. | Set global grab for this widget.
  438. |
  439. | A global grab directs all events to this and
  440. | descendant widgets on the display. Use with caution -
  441. | other applications do not get events anymore.
  442. |
  443. | grab_status(self)
  444. | Return None, "local" or "global" if this widget has
  445. | no, a local or a global grab.
  446. |
  447. | grid_anchor(self, anchor=None)
  448. | The anchor value controls how to place the grid within the
  449. | master when no row/column has any weight.
  450. |
  451. | The default anchor is nw.
  452. |
  453. | grid_bbox(self, column=None, row=None, col2=None, row2=None)
  454. | Return a tuple of integer coordinates for the bounding
  455. | box of this widget controlled by the geometry manager grid.
  456. |
  457. | If COLUMN, ROW is given the bounding box applies from
  458. | the cell with row and column 0 to the specified
  459. | cell. If COL2 and ROW2 are given the bounding box
  460. | starts at that cell.
  461. |
  462. | The returned integers specify the offset of the upper left
  463. | corner in the master widget and the width and height.
  464. |
  465. | grid_columnconfigure(self, index, cnf={}, **kw)
  466. | Configure column INDEX of a grid.
  467. |
  468. | Valid resources are minsize (minimum size of the column),
  469. | weight (how much does additional space propagate to this column)
  470. | and pad (how much space to let additionally).
  471. |
  472. | grid_location(self, x, y)
  473. | Return a tuple of column and row which identify the cell
  474. | at which the pixel at position X and Y inside the master
  475. | widget is located.
  476. |
  477. | grid_propagate(self, flag=['_noarg_'])
  478. | Set or get the status for propagation of geometry information.
  479. |
  480. | A boolean argument specifies whether the geometry information
  481. | of the slaves will determine the size of this widget. If no argument
  482. | is given, the current setting will be returned.
  483. |
  484. | grid_rowconfigure(self, index, cnf={}, **kw)
  485. | Configure row INDEX of a grid.
  486. |
  487. | Valid resources are minsize (minimum size of the row),
  488. | weight (how much does additional space propagate to this row)
  489. | and pad (how much space to let additionally).
  490. |
  491. | grid_size(self)
  492. | Return a tuple of the number of column and rows in the grid.
  493. |
  494. | grid_slaves(self, row=None, column=None)
  495. | Return a list of all slaves of this widget
  496. | in its packing order.
  497. |
  498. | image_names(self)
  499. | Return a list of all existing image names.
  500. |
  501. | image_types(self)
  502. | Return a list of all available image types (e.g. photo bitmap).
  503. |
  504. | info_patchlevel(self)
  505. | Returns the exact version of the Tcl library.
  506. |
  507. | keys(self)
  508. | Return a list of all resource names of this widget.
  509. |
  510. | lift = tkraise(self, aboveThis=None)
  511. |
  512. | lower(self, belowThis=None)
  513. | Lower this widget in the stacking order.
  514. |
  515. | mainloop(self, n=0)
  516. | Call the mainloop of Tk.
  517. |
  518. | nametowidget(self, name)
  519. | Return the Tkinter instance of a widget identified by
  520. | its Tcl name NAME.
  521. |
  522. | option_add(self, pattern, value, priority=None)
  523. | Set a VALUE (second parameter) for an option
  524. | PATTERN (first parameter).
  525. |
  526. | An optional third parameter gives the numeric priority
  527. | (defaults to 80).
  528. |
  529. | option_clear(self)
  530. | Clear the option database.
  531. |
  532. | It will be reloaded if option_add is called.
  533. |
  534. | option_get(self, name, className)
  535. | Return the value for an option NAME for this widget
  536. | with CLASSNAME.
  537. |
  538. | Values with higher priority override lower values.
  539. |
  540. | option_readfile(self, fileName, priority=None)
  541. | Read file FILENAME into the option database.
  542. |
  543. | An optional second parameter gives the numeric
  544. | priority.
  545. |
  546. | pack_propagate(self, flag=['_noarg_'])
  547. | Set or get the status for propagation of geometry information.
  548. |
  549. | A boolean argument specifies whether the geometry information
  550. | of the slaves will determine the size of this widget. If no argument
  551. | is given the current setting will be returned.
  552. |
  553. | pack_slaves(self)
  554. | Return a list of all slaves of this widget
  555. | in its packing order.
  556. |
  557. | place_slaves(self)
  558. | Return a list of all slaves of this widget
  559. | in its packing order.
  560. |
  561. | propagate = pack_propagate(self, flag=['_noarg_'])
  562. |
  563. | quit(self)
  564. | Quit the Tcl interpreter. All widgets will be destroyed.
  565. |
  566. | register = _register(self, func, subst=None, needcleanup=1)
  567. |
  568. | rowconfigure = grid_rowconfigure(self, index, cnf={}, **kw)
  569. |
  570. | selection_clear(self, **kw)
  571. | Clear the current X selection.
  572. |
  573. | selection_get(self, **kw)
  574. | Return the contents of the current X selection.
  575. |
  576. | A keyword parameter selection specifies the name of
  577. | the selection and defaults to PRIMARY. A keyword
  578. | parameter displayof specifies a widget on the display
  579. | to use. A keyword parameter type specifies the form of data to be
  580. | fetched, defaulting to STRING except on X11, where UTF8_STRING is tried
  581. | before STRING.
  582. |
  583. | selection_handle(self, command, **kw)
  584. | Specify a function COMMAND to call if the X
  585. | selection owned by this widget is queried by another
  586. | application.
  587. |
  588. | This function must return the contents of the
  589. | selection. The function will be called with the
  590. | arguments OFFSET and LENGTH which allows the chunking
  591. | of very long selections. The following keyword
  592. | parameters can be provided:
  593. | selection - name of the selection (default PRIMARY),
  594. | type - type of the selection (e.g. STRING, FILE_NAME).
  595. |
  596. | selection_own(self, **kw)
  597. | Become owner of X selection.
  598. |
  599. | A keyword parameter selection specifies the name of
  600. | the selection (default PRIMARY).
  601. |
  602. | selection_own_get(self, **kw)
  603. | Return owner of X selection.
  604. |
  605. | The following keyword parameter can
  606. | be provided:
  607. | selection - name of the selection (default PRIMARY),
  608. | type - type of the selection (e.g. STRING, FILE_NAME).
  609. |
  610. | send(self, interp, cmd, *args)
  611. | Send Tcl command CMD to different interpreter INTERP to be executed.
  612. |
  613. | setvar(self, name='PY_VAR', value='1')
  614. | Set Tcl variable NAME to VALUE.
  615. |
  616. | size = grid_size(self)
  617. |
  618. | slaves = pack_slaves(self)
  619. |
  620. | tk_bisque(self)
  621. | Change the color scheme to light brown as used in Tk 3.6 and before.
  622. |
  623. | tk_focusFollowsMouse(self)
  624. | The widget under mouse will get automatically focus. Can not
  625. | be disabled easily.
  626. |
  627. | tk_focusNext(self)
  628. | Return the next widget in the focus order which follows
  629. | widget which has currently the focus.
  630. |
  631. | The focus order first goes to the next child, then to
  632. | the children of the child recursively and then to the
  633. | next sibling which is higher in the stacking order. A
  634. | widget is omitted if it has the takefocus resource set
  635. | to 0.
  636. |
  637. | tk_focusPrev(self)
  638. | Return previous widget in the focus order. See tk_focusNext for details.
  639. |
  640. | tk_setPalette(self, *args, **kw)
  641. | Set a new color scheme for all widget elements.
  642. |
  643. | A single color as argument will cause that all colors of Tk
  644. | widget elements are derived from this.
  645. | Alternatively several keyword parameters and its associated
  646. | colors can be given. The following keywords are valid:
  647. | activeBackground, foreground, selectColor,
  648. | activeForeground, highlightBackground, selectBackground,
  649. | background, highlightColor, selectForeground,
  650. | disabledForeground, insertBackground, troughColor.
  651. |
  652. | tk_strictMotif(self, boolean=None)
  653. | Set Tcl internal variable, whether the look and feel
  654. | should adhere to Motif.
  655. |
  656. | A parameter of 1 means adhere to Motif (e.g. no color
  657. | change if mouse passes over slider).
  658. | Returns the set value.
  659. |
  660. | tkraise(self, aboveThis=None)
  661. | Raise this widget in the stacking order.
  662. |
  663. | unbind(self, sequence, funcid=None)
  664. | Unbind for this widget the event SEQUENCE.
  665. |
  666. | If FUNCID is given, only unbind the function identified with FUNCID
  667. | and also delete the corresponding Tcl command.
  668. |
  669. | Otherwise destroy the current binding for SEQUENCE, leaving SEQUENCE
  670. | unbound.
  671. |
  672. | unbind_all(self, sequence)
  673. | Unbind for all widgets for event SEQUENCE all functions.
  674. |
  675. | unbind_class(self, className, sequence)
  676. | Unbind for all widgets with bindtag CLASSNAME for event SEQUENCE
  677. | all functions.
  678. |
  679. | update(self)
  680. | Enter event loop until all pending events have been processed by Tcl.
  681. |
  682. | update_idletasks(self)
  683. | Enter event loop until all idle callbacks have been called. This
  684. | will update the display of windows but not process events caused by
  685. | the user.
  686. |
  687. | wait_variable(self, name='PY_VAR')
  688. | Wait until the variable is modified.
  689. |
  690. | A parameter of type IntVar, StringVar, DoubleVar or
  691. | BooleanVar must be given.
  692. |
  693. | wait_visibility(self, window=None)
  694. | Wait until the visibility of a WIDGET changes
  695. | (e.g. it appears).
  696. |
  697. | If no parameter is given self is used.
  698. |
  699. | wait_window(self, window=None)
  700. | Wait until a WIDGET is destroyed.
  701. |
  702. | If no parameter is given self is used.
  703. |
  704. | waitvar = wait_variable(self, name='PY_VAR')
  705. |
  706. | winfo_atom(self, name, displayof=0)
  707. | Return integer which represents atom NAME.
  708. |
  709. | winfo_atomname(self, id, displayof=0)
  710. | Return name of atom with identifier ID.
  711. |
  712. | winfo_cells(self)
  713. | Return number of cells in the colormap for this widget.
  714. |
  715. | winfo_children(self)
  716. | Return a list of all widgets which are children of this widget.
  717. |
  718. | winfo_class(self)
  719. | Return window class name of this widget.
  720. |
  721. | winfo_colormapfull(self)
  722. | Return True if at the last color request the colormap was full.
  723. |
  724. | winfo_containing(self, rootX, rootY, displayof=0)
  725. | Return the widget which is at the root coordinates ROOTX, ROOTY.
  726. |
  727. | winfo_depth(self)
  728. | Return the number of bits per pixel.
  729. |
  730. | winfo_exists(self)
  731. | Return true if this widget exists.
  732. |
  733. | winfo_fpixels(self, number)
  734. | Return the number of pixels for the given distance NUMBER
  735. | (e.g. "3c") as float.
  736. |
  737. | winfo_geometry(self)
  738. | Return geometry string for this widget in the form "widthxheight+X+Y".
  739. |
  740. | winfo_height(self)
  741. | Return height of this widget.
  742. |
  743. | winfo_id(self)
  744. | Return identifier ID for this widget.
  745. |
  746. | winfo_interps(self, displayof=0)
  747. | Return the name of all Tcl interpreters for this display.
  748. |
  749. | winfo_ismapped(self)
  750. | Return true if this widget is mapped.
  751. |
  752. | winfo_manager(self)
  753. | Return the window manager name for this widget.
  754. |
  755. | winfo_name(self)
  756. | Return the name of this widget.
  757. |
  758. | winfo_parent(self)
  759. | Return the name of the parent of this widget.
  760. |
  761. | winfo_pathname(self, id, displayof=0)
  762. | Return the pathname of the widget given by ID.
  763. |
  764. | winfo_pixels(self, number)
  765. | Rounded integer value of winfo_fpixels.
  766. |
  767. | winfo_pointerx(self)
  768. | Return the x coordinate of the pointer on the root window.
  769. |
  770. | winfo_pointerxy(self)
  771. | Return a tuple of x and y coordinates of the pointer on the root window.
  772. |
  773. | winfo_pointery(self)
  774. | Return the y coordinate of the pointer on the root window.
  775. |
  776. | winfo_reqheight(self)
  777. | Return requested height of this widget.
  778. |
  779. | winfo_reqwidth(self)
  780. | Return requested width of this widget.
  781. |
  782. | winfo_rgb(self, color)
  783. | Return a tuple of integer RGB values in range(65536) for color in this widget.
  784. |
  785. | winfo_rootx(self)
  786. | Return x coordinate of upper left corner of this widget on the
  787. | root window.
  788. |
  789. | winfo_rooty(self)
  790. | Return y coordinate of upper left corner of this widget on the
  791. | root window.
  792. |
  793. | winfo_screen(self)
  794. | Return the screen name of this widget.
  795. |
  796. | winfo_screencells(self)
  797. | Return the number of the cells in the colormap of the screen
  798. | of this widget.
  799. |
  800. | winfo_screendepth(self)
  801. | Return the number of bits per pixel of the root window of the
  802. | screen of this widget.
  803. |
  804. | winfo_screenheight(self)
  805. | Return the number of pixels of the height of the screen of this widget
  806. | in pixel.
  807. |
  808. | winfo_screenmmheight(self)
  809. | Return the number of pixels of the height of the screen of
  810. | this widget in mm.
  811. |
  812. | winfo_screenmmwidth(self)
  813. | Return the number of pixels of the width of the screen of
  814. | this widget in mm.
  815. |
  816. | winfo_screenvisual(self)
  817. | Return one of the strings directcolor, grayscale, pseudocolor,
  818. | staticcolor, staticgray, or truecolor for the default
  819. | colormodel of this screen.
  820. |
  821. | winfo_screenwidth(self)
  822. | Return the number of pixels of the width of the screen of
  823. | this widget in pixel.
  824. |
  825. | winfo_server(self)
  826. | Return information of the X-Server of the screen of this widget in
  827. | the form "XmajorRminor vendor vendorVersion".
  828. |
  829. | winfo_toplevel(self)
  830. | Return the toplevel widget of this widget.
  831. |
  832. | winfo_viewable(self)
  833. | Return true if the widget and all its higher ancestors are mapped.
  834. |
  835. | winfo_visual(self)
  836. | Return one of the strings directcolor, grayscale, pseudocolor,
  837. | staticcolor, staticgray, or truecolor for the
  838. | colormodel of this widget.
  839. |
  840. | winfo_visualid(self)
  841. | Return the X identifier for the visual for this widget.
  842. |
  843. | winfo_visualsavailable(self, includeids=False)
  844. | Return a list of all visuals available for the screen
  845. | of this widget.
  846. |
  847. | Each item in the list consists of a visual name (see winfo_visual), a
  848. | depth and if includeids is true is given also the X identifier.
  849. |
  850. | winfo_vrootheight(self)
  851. | Return the height of the virtual root window associated with this
  852. | widget in pixels. If there is no virtual root window return the
  853. | height of the screen.
  854. |
  855. | winfo_vrootwidth(self)
  856. | Return the width of the virtual root window associated with this
  857. | widget in pixel. If there is no virtual root window return the
  858. | width of the screen.
  859. |
  860. | winfo_vrootx(self)
  861. | Return the x offset of the virtual root relative to the root
  862. | window of the screen of this widget.
  863. |
  864. | winfo_vrooty(self)
  865. | Return the y offset of the virtual root relative to the root
  866. | window of the screen of this widget.
  867. |
  868. | winfo_width(self)
  869. | Return the width of this widget.
  870. |
  871. | winfo_x(self)
  872. | Return the x coordinate of the upper left corner of this widget
  873. | in the parent.
  874. |
  875. | winfo_y(self)
  876. | Return the y coordinate of the upper left corner of this widget
  877. | in the parent.
  878. |
  879. | ----------------------------------------------------------------------
  880. | Data descriptors inherited from tkinter.Misc:
  881. |
  882. | __dict__
  883. | dictionary for instance variables
  884. |
  885. | __weakref__
  886. | list of weak references to the object
  887. |
  888. | ----------------------------------------------------------------------
  889. | Methods inherited from tkinter.Pack:
  890. |
  891. | forget = pack_forget(self)
  892. |
  893. | info = pack_info(self)
  894. |
  895. | pack = pack_configure(self, cnf={}, **kw)
  896. |
  897. | pack_configure(self, cnf={}, **kw)
  898. | Pack a widget in the parent widget. Use as options:
  899. | after=widget - pack it after you have packed widget
  900. | anchor=NSEW (or subset) - position widget according to
  901. | given direction
  902. | before=widget - pack it before you will pack widget
  903. | expand=bool - expand widget if parent size grows
  904. | fill=NONE or X or Y or BOTH - fill widget if widget grows
  905. | in=master - use master to contain this widget
  906. | in_=master - see 'in' option description
  907. | ipadx=amount - add internal padding in x direction
  908. | ipady=amount - add internal padding in y direction
  909. | padx=amount - add padding in x direction
  910. | pady=amount - add padding in y direction
  911. | side=TOP or BOTTOM or LEFT or RIGHT - where to add this widget.
  912. |
  913. | pack_forget(self)
  914. | Unmap this widget and do not use it for the packing order.
  915. |
  916. | pack_info(self)
  917. | Return information about the packing options
  918. | for this widget.
  919. |
  920. | ----------------------------------------------------------------------
  921. | Methods inherited from tkinter.Place:
  922. |
  923. | place = place_configure(self, cnf={}, **kw)
  924. |
  925. | place_configure(self, cnf={}, **kw)
  926. | Place a widget in the parent widget. Use as options:
  927. | in=master - master relative to which the widget is placed
  928. | in_=master - see 'in' option description
  929. | x=amount - locate anchor of this widget at position x of master
  930. | y=amount - locate anchor of this widget at position y of master
  931. | relx=amount - locate anchor of this widget between 0.0 and 1.0
  932. | relative to width of master (1.0 is right edge)
  933. | rely=amount - locate anchor of this widget between 0.0 and 1.0
  934. | relative to height of master (1.0 is bottom edge)
  935. | anchor=NSEW (or subset) - position anchor according to given direction
  936. | width=amount - width of this widget in pixel
  937. | height=amount - height of this widget in pixel
  938. | relwidth=amount - width of this widget between 0.0 and 1.0
  939. | relative to width of master (1.0 is the same width
  940. | as the master)
  941. | relheight=amount - height of this widget between 0.0 and 1.0
  942. | relative to height of master (1.0 is the same
  943. | height as the master)
  944. | bordermode="inside" or "outside" - whether to take border width of
  945. | master widget into account
  946. |
  947. | place_forget(self)
  948. | Unmap this widget.
  949. |
  950. | place_info(self)
  951. | Return information about the placing options
  952. | for this widget.
  953. |
  954. | ----------------------------------------------------------------------
  955. | Methods inherited from tkinter.Grid:
  956. |
  957. | grid = grid_configure(self, cnf={}, **kw)
  958. |
  959. | grid_configure(self, cnf={}, **kw)
  960. | Position a widget in the parent widget in a grid. Use as options:
  961. | column=number - use cell identified with given column (starting with 0)
  962. | columnspan=number - this widget will span several columns
  963. | in=master - use master to contain this widget
  964. | in_=master - see 'in' option description
  965. | ipadx=amount - add internal padding in x direction
  966. | ipady=amount - add internal padding in y direction
  967. | padx=amount - add padding in x direction
  968. | pady=amount - add padding in y direction
  969. | row=number - use cell identified with given row (starting with 0)
  970. | rowspan=number - this widget will span several rows
  971. | sticky=NSEW - if cell is larger on which sides will this
  972. | widget stick to the cell boundary
  973. |
  974. | grid_forget(self)
  975. | Unmap this widget.
  976. |
  977. | grid_info(self)
  978. | Return information about the options
  979. | for positioning this widget in a grid.
  980. |
  981. | grid_remove(self)
  982. | Unmap this widget but remember the grid options.
  983. |
  984. | location = grid_location(self, x, y)
  985. None
  986. [Finished in 588ms]

通过dir来查看Meter支持的属性和方法

['_Misc__winfo_getint', '_Misc__winfo_parseitem', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_bind', '_configure', '_configure_get', '_configure_set', '_displayof', '_do', '_draw_base_image', '_draw_meter', '_draw_solid_meter', '_draw_striped_meter', '_getboolean', '_getconfigure', '_getconfigure1', '_getdoubles', '_getints', '_grid_configure', '_gridconvvalue', '_last_child_ids', '_lookup_style_option', '_meter_value', '_nametowidget', '_noarg_', '_on_dial_interact', '_on_theme_change', '_options', '_register', '_report_exception', '_root', '_set_arc_offset_range', '_set_interactive_bind', '_set_meter_text', '_set_show_text', '_set_subtext', '_set_text_center', '_set_text_left', '_set_text_right', '_set_widget_colors', '_setup', '_setup_widget', '_subst_format', '_subst_format_str', '_substitute', '_tclCommands', '_unbind', '_windowingsystem', 'after', 'after_cancel', 'after_idle', 'anchor', 'bbox', 'bell', 'bind', 'bind_all', 'bind_class', 'bindtags', 'cget', 'clipboard_append', 'clipboard_clear', 'clipboard_get', 'columnconfigure', 'config', 'configure', 'deletecommand', 'destroy', 'event_add', 'event_delete', 'event_generate', 'event_info', 'focus', 'focus_displayof', 'focus_force', 'focus_get', 'focus_lastfor', 'focus_set', 'forget', 'getboolean', 'getdouble', 'getint', 'getvar', 'grab_current', 'grab_release', 'grab_set', 'grab_set_global', 'grab_status', 'grid', 'grid_anchor', 'grid_bbox', 'grid_columnconfigure', 'grid_configure', 'grid_forget', 'grid_info', 'grid_location', 'grid_propagate', 'grid_remove', 'grid_rowconfigure', 'grid_size', 'grid_slaves', 'identify', 'image_names', 'image_types', 'info', 'info_patchlevel', 'instate', 'keys', 'lift', 'location', 'lower', 'mainloop', 'nametowidget', 'option_add', 'option_clear', 'option_get', 'option_readfile', 'pack', 'pack_configure', 'pack_forget', 'pack_info', 'pack_propagate', 'pack_slaves', 'place', 'place_configure', 'place_forget', 'place_info', 'place_slaves', 'propagate', 'quit', 'register', 'rowconfigure', 'selection_clear', 'selection_get', 'selection_handle', 'selection_own', 'selection_own_get', 'send', 'setvar', 'size', 'slaves', 'state', 'step', 'tk_bisque', 'tk_focusFollowsMouse', 'tk_focusNext', 'tk_focusPrev', 'tk_setPalette', 'tk_strictMotif', 'tkraise', 'unbind', 'unbind_all', 'unbind_class', 'update', 'update_idletasks', 'wait_variable', 'wait_visibility', 'wait_window', 'waitvar', 'winfo_atom', 'winfo_atomname', 'winfo_cells', 'winfo_children', 'winfo_class', 'winfo_colormapfull', 'winfo_containing', 'winfo_depth', 'winfo_exists', 'winfo_fpixels', 'winfo_geometry', 'winfo_height', 'winfo_id', 'winfo_interps', 'winfo_ismapped', 'winfo_manager', 'winfo_name', 'winfo_parent', 'winfo_pathname', 'winfo_pixels', 'winfo_pointerx', 'winfo_pointerxy', 'winfo_pointery', 'winfo_reqheight', 'winfo_reqwidth', 'winfo_rgb', 'winfo_rootx', 'winfo_rooty', 'winfo_screen', 'winfo_screencells', 'winfo_screendepth', 'winfo_screenheight', 'winfo_screenmmheight', 'winfo_screenmmwidth', 'winfo_screenvisual', 'winfo_screenwidth', 'winfo_server', 'winfo_toplevel', 'winfo_viewable', 'winfo_visual', 'winfo_visualid', 'winfo_visualsavailable', 'winfo_vrootheight', 'winfo_vrootwidth', 'winfo_vrootx', 'winfo_vrooty', 'winfo_width', 'winfo_x', 'winfo_y']
[Finished in 455ms]

二:Meter创建

首先我们通过官方的一个例子来看Meter如何创建的

  1. import ttkbootstrap as ttk
  2. from ttkbootstrap.constants import *
  3. app = ttk.Window()
  4. meter = ttk.Meter(
  5. metersize=180,
  6. padding=5,
  7. amountused=25,
  8. metertype="semi",
  9. subtext="miles per hour",
  10. interactive=True,
  11. )
  12. meter.pack()
  13. # update the amount used directly
  14. meter.configure(amountused = 50)
  15. # update the amount used with another widget
  16. entry = ttk.Entry(textvariable=meter.amountusedvar)
  17. entry.pack(fill=X)
  18. # increment the amount by 10 steps
  19. meter.step(10)
  20. # decrement the amount by 15 steps
  21. meter.step(-15)
  22. # update the subtext
  23. meter.configure(subtext="loading...")
  24. app.mainloop()

三:Meter选项

以下是Meter接口的选项

__init__(self, master=None, bootstyle='default', arcrange=None, arcoffset=None, amounttotal=100, amountused=0, wedgesize=0, metersize=200, metertype='full', meterthickness=10, showtext=True, interactive=False, stripethickness=0, textleft=None, textright=None, textfont='-size 20 -weight bold', subtext=None, subtextstyle='default', subtextfont='-size 10', stepsize=1, **kwargs)

与官方的文档现在已经有些出入了,里面的一些字段也变更了

选项解释说明
master (Widget)父窗口
arcrange (int)从起点到终点的弧度范围。
arcoffset (int)偏移圆弧起始位置的量(以度为单位)。0位于3点钟方向。
amounttotal (int)仪表的最大值
amountused (int)仪表的当前值;如果“showtext”属性设置为True,则显示在中心标签中。
wedgesize (int)设置圆弧周围指示器楔块的长度。如果大于0,则此楔块将设置为以当前仪表值为中心的指示器。
metersize (int)Meter控件的大小
bootstyle (str)设置Meter的样式,选项:primary,secondary, success, info, warning, danger, light, dark.
metertype ('full', 'semi')将仪表显示为圆形或半圆。
meterthickness (int)指示器的厚度。
showtext (bool)指示是否在仪表上显示左侧、中间和右侧的文本标签。
interactive (bool)表示用户可以通过鼠标交互调整仪表值。
stripethickness (int)指示器可以显示为实心带,也可以显示为圆弧周围的条纹楔。如果该值大于0,指示器将从实心变为条纹,其中该值为条纹(或楔)的厚度。
textleft (str)插入到中心文本左侧的短字符串。
textright (str)插入到中心文本右侧的短字符串。
textfont (Union[str, Font])用于呈现中心文本的字体。
subtext (str)显示在中心文本下方的补充文本。
subtextstyle (str)设置subtext文本样式
subtextfont (Union[str, Font])设置subtext文本字体
stepsize (int)设置通过鼠标交互递增时更改仪表指示器的量。

下面再通过两个例子来展示如上选项的使用

  1. from ttkbootstrap import Style
  2. from ttkbootstrap.widgets import Meter
  3. style = Style('cosmo')
  4. root = style.master
  5. root.title('ttkbootstrap')
  6. print(help(Meter))
  7. m1 = Meter(metersize=180, padding=20, amountused=25, metertype='semi', subtext='miles per hour', interactive=True)
  8. m1.grid(row=0, column=0)
  9. m2 = Meter(metersize=180, padding=20, amountused=1800, amounttotal=2600, subtext='storage used', textright='gb',
  10. bootstyle='info.TMeter', stripethickness=10, interactive=True)
  11. m2.grid(row=0, column=1)
  12. m3 = Meter(metersize=180, padding=20, stripethickness=2, amountused=40, subtext='project capacity', textright='%',
  13. bootstyle='success.TMeter', interactive=True)
  14. m3.grid(row=1, column=0)
  15. m4 = Meter(metersize=180, padding=20, amounttotal=280, arcrange=180, arcoffset=-180, amountused=75, textright='°',
  16. subtext='heat temperature', wedgesize=5, bootstyle='danger.TMeter', interactive=True)
  17. m4.grid(row=1, column=1)
  18. root.mainloop()

下面一个利用Meter来动态展示获取网卡io统计信息,也可以理解为网速的例子

  1. import psutil,time,threading
  2. import ttkbootstrap as ttk
  3. from ttkbootstrap.constants import *
  4. root = ttk.Window()
  5. ttk.Meter(
  6. master=root,
  7. bootstyle=DEFAULT,
  8. metertype="full",#将仪表显示为一个完整的圆形或半圆形(semi)
  9. wedgesize=5, #设置弧周围的指示器楔形长度,如果大于 0,则此楔形设置为以当前仪表值为中心的指示器
  10. amounttotal=50, #仪表的最大值,默认100
  11. amountused=10, #仪表的当前值
  12. metersize=200,#仪表大小
  13. showtext=True, #指示是否在仪表上显示左、中、右文本标签
  14. interactive=True, #是否可以手动调节数字的大小
  15. textleft='左边', #插入到中心文本左侧的短字符串
  16. textright='右边',
  17. textfont="-size 30", #中间数字大小
  18. subtext="文本",
  19. subtextstyle=DEFAULT,
  20. subtextfont="-size 20",#文本大小
  21. ).pack(side=ttk.LEFT, padx=5)
  22. def _():
  23. meter = ttk.Meter(
  24. metersize=180,
  25. padding=50,
  26. amountused=0,
  27. metertype="semi",
  28. subtext="当前网速(kB/s)",
  29. subtextstyle="warning",
  30. interactive=False,
  31. bootstyle='primary',
  32. )
  33. meter.pack(side=ttk.LEFT, padx=5)
  34. while True:
  35. meter.configure(amountused=round(getNet(),2))
  36. def getNet():
  37. recv_before = psutil.net_io_counters().bytes_recv
  38. time.sleep(1)
  39. recv_now = psutil.net_io_counters().bytes_recv
  40. recv = (recv_now - recv_before)/1024
  41. return recv
  42. t = threading.Thread(target=_)
  43. t.setDaemon(True)
  44. t.start()
  45. root.mainloop()

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/983619?site=
推荐阅读
相关标签
  

闽ICP备14008679号