Python Tkinter Panel Widget and Dialog Box with Source Code

Introduction

Python Tkinter Panel Widget and Dialog Box is for displaying the layer of canvas on a GUI based menu bar. So, the panel widget and dialog boxes are packed and the geometry manager makes the full GUI widget box to hold on inner edge. Mostly, python Tkinter possess three kind of layers which are pack, grid and place.

The functionality of the panel widget the whole pack of widget where layout manager manages pack, grid and place. Also, three items should not be mixed with the master window panel because geometry manager serves several functionality.

  • Pack: The pack methods help to organize widgets in block before putting them in the master widget.
  • Grid:  The grid methods help to place the widget in a 2-dimentional table by separating them in rows and columns.
  • Place: The place methods is a simple and a easy way which is managed by three general managers.  It helps user to set the size and the position of window in a relative way.

Background Reading

Python Tkinter Panel Widget and Dialog Box consist of panned widget and a password authentication dialog box. Here, panned widget are managed in a row and column order where user can swipe the panel left to right.  Also, the dialog box  contains two panel where you have to enter the right password to get access of another panel. The dialog box contains two buttons where one is OK button and another is CANCEL button.

Technology used

  1. Python as a programming language.
  2. Tkinter as a library for GUI based application.
  3. Pycharm as an IDE.
  4. pmw as a library.
Panel widget

Panel widget

Dialog box

Dialog box

Therefore things to know

  • You have to download python 2 or python 3 (sudo apt-get install python3).
  • You have to install pip or pip3 for downloading different libraries (sudo apt-get install python-pip).
  • Also, you can install Tkinter library with sudo pip install tkinter.
  • Likewise, you can install pycharm or Atom or Sublime text for an IDE or you can simple sudo nano filename.
  • You have to install pmw library with sudo pip install pmw.

Therefore code of panel widget

from Tkinter import *
import Pmw
root = Tk()
root.option_readfile('optionDB')
root.title('PanedWidget')
Pmw.initialise()

pane = Pmw.PanedWidget(root, hull_width=400, hull_height=300)
pane.add('top', min=100)
pane.add('bottom', min=100)

topPane = Pmw.PanedWidget(pane.pane('top'), orient=HORIZONTAL)
for num in range(4):
if num == 1:
name = 'Fixed\nSize'
topPane.add(name, min=.2, max=.2)
else:
name = 'Pane\n' + str(num)
topPane.add(name, min=.1, size=.25)
button = Button(topPane.pane(name), text=name)
button.pack(expand=1)

topPane.pack(expand=1, fill=BOTH)
pane.pack(expand=1, fill=BOTH)

root.mainloop()

Therefore code of dialogbox

from Tkinter import *
import Pmw
root = Tk()
root.option_readfile('optionDB')
root.title('PromptDialog')
Pmw.initialise()

dialog = Pmw.PromptDialog(root, title='Password', label_text='Password:',
entryfield_labelpos=N, entry_show='*', defaultbutton=0,
buttons=('OK', 'Cancel'))

result = dialog.activate()

print 'You selected', result

root.mainloop()

You may also like...

Leave a Reply

avatar
  Subscribe  
Notify of