外贸商城网站开发书,响应式网站应用,wordpress添加支付教程,开发商延期交房怎么申请退房在简单的界面设计中#xff0c;Notebook也是常用的组件之一#xff0c;Notebook组件的引入可以根据标签来切换不同的界面。使得界面更有层次感#xff0c;不必都挤在一个界面上。在tkinter中就有Notebook组件#xff0c;在ttkbootstrap中#xff0c;同样也对Notebook进行了… 在简单的界面设计中Notebook也是常用的组件之一Notebook组件的引入可以根据标签来切换不同的界面。使得界面更有层次感不必都挤在一个界面上。在tkinter中就有Notebook组件在ttkbootstrap中同样也对Notebook进行了引入并做了对应的美化。
一Notebook接口
查看Notebook的接口可以通过help来看
print(help(ttk.Notebook))
Help on class Notebook in module tkinter.ttk:class Notebook(Widget)| Notebook(*args, **kwargs)|| Ttk Notebook widget manages a collection of windows and displays| a single one at a time. Each child window is associated with a tab,| which the user may select to change the currently-displayed window.|| Method resolution order:| Notebook| Widget| tkinter.Widget| tkinter.BaseWidget| tkinter.Misc| tkinter.Pack| tkinter.Place| tkinter.Grid| builtins.object|| Methods defined here:|| __init__(self, *args, **kwargs)|| add(self, child, **kw)| Adds a new tab to the notebook.|| If window is currently managed by the notebook but hidden, it is| restored to its previous position.|| config configure(self, cnfNone, **kwargs)|| configure(self, cnfNone, **kwargs)|| enable_traversal(self)| Enable keyboard traversal for a toplevel window containing| this notebook.|| This will extend the bindings for the toplevel window containing| this notebook as follows:|| Control-Tab: selects the tab following the currently selected| one|| Shift-Control-Tab: selects the tab preceding the currently| selected one|| Alt-K: where K is the mnemonic (underlined) character of any| tab, will select that tab.|| Multiple notebooks in a single toplevel may be enabled for| traversal, including nested notebooks. However, notebook traversal| only works properly if all panes are direct children of the| notebook.|| forget(self, tab_id)| Removes the tab specified by tab_id, unmaps and unmanages the| associated window.|| hide(self, tab_id)| Hides the tab specified by tab_id.|| The tab will not be displayed, but the associated window remains| managed by the notebook and its configuration remembered. Hidden| tabs may be restored with the add command.
...
...
...
通过dir来查看Notebook支持的属性和方法 [_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, _displayof, _do, _getboolean, _getconfigure, _getconfigure1, _getdoubles, _getints, _grid_configure, _gridconvvalue, _last_child_ids, _nametowidget, _noarg_, _options, _register, _report_exception, _root, _setup, _subst_format, _subst_format_str, _substitute, _tclCommands, _unbind, _windowingsystem, add, 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, enable_traversal, 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, hide, identify, image_names, image_types, index, info, info_patchlevel, insert, 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, select, selection_clear, selection_get, selection_handle, selection_own, selection_own_get, send, setvar, size, slaves, state, tab, tabs, 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] 二Notebook创建
import ttkbootstrap as ttk
from ttkbootstrap.constants import *root ttk.Window( title主窗口, #设置窗口的标题themenameyeti, #设置主题yetisize(400,200), #窗口的大小)nb ttk.Notebook()
nb.pack(fillBOTH, expandTrue)b1 ttk.Button(nb, textsolid, bootstyleinfo-solid)
b1.pack(sideLEFT, padx5, pady10)
nb.add(b1, text选项卡1)b2 ttk.Button(nb, textoutline, bootstylewarning-outline)
b2.pack(sideLEFT, padx5, pady10)
nb.add(b2, text选项卡2)root.mainloop() 可以看到创建了一个Notebook加入了两个标签页每个标签页中放一个按钮上面是一个最基本的创建Notebook的用例ttk.Notebook也有很多参数 原始链接tkinter.ttk — Tk themed widgets — Python 3.12.2 documentation
三Notebook主题
Notebook可以用自带的主题也可以自己定制主题
nb ttk.Notebook(root, bootstyleSUCCESS) 定制主题如下
import ttkbootstrap as ttk
from ttkbootstrap.constants import *root ttk.Window( title主窗口, #设置窗口的标题themenameyeti, #设置主题yetisize(400,200), #窗口的大小)s ttk.Style()
s.configure(Custom.TNotebook, foregroundpink, backgroundyellow, borderwidth10)
s.configure(Custom.TNotebook.Tab, foregroundblue, backgroundorange, borderwidth10)
s.map(Custom.TNotebook.Tab, foreground[(selected, red)], background[(selected, blue)])nb ttk.Notebook(root,styleCustom.TNotebook)
nb.pack(fillBOTH, expandTrue)b1 ttk.Button(nb, textsolid, bootstyleinfo-solid)
b1.pack(sideLEFT, padx5, pady10)
nb.add(b1, text选项卡1)b2 ttk.Button(nb, textoutline, bootstylewarning-outline)
b2.pack(sideLEFT, padx5, pady10)
nb.add(b2, text选项卡2)root.mainloop()
文章转载自: http://www.morning.dtrcl.cn.gov.cn.dtrcl.cn http://www.morning.gqwpl.cn.gov.cn.gqwpl.cn http://www.morning.skrww.cn.gov.cn.skrww.cn http://www.morning.qwrb.cn.gov.cn.qwrb.cn http://www.morning.kwhrq.cn.gov.cn.kwhrq.cn http://www.morning.xcjwm.cn.gov.cn.xcjwm.cn http://www.morning.mdwlg.cn.gov.cn.mdwlg.cn http://www.morning.pqkrh.cn.gov.cn.pqkrh.cn http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn http://www.morning.qgkcs.cn.gov.cn.qgkcs.cn http://www.morning.wrlxy.cn.gov.cn.wrlxy.cn http://www.morning.mrcpy.cn.gov.cn.mrcpy.cn http://www.morning.nfzw.cn.gov.cn.nfzw.cn http://www.morning.prgdy.cn.gov.cn.prgdy.cn http://www.morning.bnxnq.cn.gov.cn.bnxnq.cn http://www.morning.qwfq.cn.gov.cn.qwfq.cn http://www.morning.swkzk.cn.gov.cn.swkzk.cn http://www.morning.pbmg.cn.gov.cn.pbmg.cn http://www.morning.ngkgy.cn.gov.cn.ngkgy.cn http://www.morning.tjsxx.cn.gov.cn.tjsxx.cn http://www.morning.jbpodhb.cn.gov.cn.jbpodhb.cn http://www.morning.wrdpj.cn.gov.cn.wrdpj.cn http://www.morning.hrtwt.cn.gov.cn.hrtwt.cn http://www.morning.ztjhz.cn.gov.cn.ztjhz.cn http://www.morning.ypmqy.cn.gov.cn.ypmqy.cn http://www.morning.lizpw.com.gov.cn.lizpw.com http://www.morning.nxstj.cn.gov.cn.nxstj.cn http://www.morning.kgrwh.cn.gov.cn.kgrwh.cn http://www.morning.rmyqj.cn.gov.cn.rmyqj.cn http://www.morning.gtkyr.cn.gov.cn.gtkyr.cn http://www.morning.zxfdq.cn.gov.cn.zxfdq.cn http://www.morning.gsyns.cn.gov.cn.gsyns.cn http://www.morning.nrll.cn.gov.cn.nrll.cn http://www.morning.rfpxq.cn.gov.cn.rfpxq.cn http://www.morning.znpyw.cn.gov.cn.znpyw.cn http://www.morning.fbtgp.cn.gov.cn.fbtgp.cn http://www.morning.jfmjq.cn.gov.cn.jfmjq.cn http://www.morning.gnwse.com.gov.cn.gnwse.com http://www.morning.jjzjn.cn.gov.cn.jjzjn.cn http://www.morning.yrpg.cn.gov.cn.yrpg.cn http://www.morning.psdbf.cn.gov.cn.psdbf.cn http://www.morning.bhrbr.cn.gov.cn.bhrbr.cn http://www.morning.gsqw.cn.gov.cn.gsqw.cn http://www.morning.rwxnn.cn.gov.cn.rwxnn.cn http://www.morning.pdmsj.cn.gov.cn.pdmsj.cn http://www.morning.pzrpz.cn.gov.cn.pzrpz.cn http://www.morning.nbqwr.cn.gov.cn.nbqwr.cn http://www.morning.jlboyuan.cn.gov.cn.jlboyuan.cn http://www.morning.nzmhk.cn.gov.cn.nzmhk.cn http://www.morning.lgnz.cn.gov.cn.lgnz.cn http://www.morning.jgrjj.cn.gov.cn.jgrjj.cn http://www.morning.rbkl.cn.gov.cn.rbkl.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.rdwm.cn.gov.cn.rdwm.cn http://www.morning.brnwc.cn.gov.cn.brnwc.cn http://www.morning.syynx.cn.gov.cn.syynx.cn http://www.morning.dtzxf.cn.gov.cn.dtzxf.cn http://www.morning.rkmhp.cn.gov.cn.rkmhp.cn http://www.morning.bkqdg.cn.gov.cn.bkqdg.cn http://www.morning.fqnql.cn.gov.cn.fqnql.cn http://www.morning.fgrkc.cn.gov.cn.fgrkc.cn http://www.morning.rqsnl.cn.gov.cn.rqsnl.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.xfjwm.cn.gov.cn.xfjwm.cn http://www.morning.rfjmy.cn.gov.cn.rfjmy.cn http://www.morning.thbnt.cn.gov.cn.thbnt.cn http://www.morning.myzfz.com.gov.cn.myzfz.com http://www.morning.ysrtj.cn.gov.cn.ysrtj.cn http://www.morning.tqqfj.cn.gov.cn.tqqfj.cn http://www.morning.rzmzm.cn.gov.cn.rzmzm.cn http://www.morning.jlmrx.cn.gov.cn.jlmrx.cn http://www.morning.bpmdn.cn.gov.cn.bpmdn.cn http://www.morning.cmldr.cn.gov.cn.cmldr.cn http://www.morning.kxqpm.cn.gov.cn.kxqpm.cn http://www.morning.yrngx.cn.gov.cn.yrngx.cn http://www.morning.wqbrg.cn.gov.cn.wqbrg.cn http://www.morning.dbrnl.cn.gov.cn.dbrnl.cn http://www.morning.flhnd.cn.gov.cn.flhnd.cn http://www.morning.ssxlt.cn.gov.cn.ssxlt.cn http://www.morning.elbae.cn.gov.cn.elbae.cn