Advertisement
gregwa

Article 30 code

Feb 6th, 2012
525
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # test1.py
  2. #! /usr/bin/env python
  3. # -*- python -*-
  4.  
  5. import sys
  6.  
  7. py2 = py30 = py31 = False
  8. version = sys.hexversion
  9. if version >= 0x020600F0 and version < 0x03000000 :
  10.     py2 = True    # Python 2.6 or 2.7
  11.     from Tkinter import *
  12.     import ttk
  13. elif version >= 0x03000000 and version < 0x03010000 :
  14.     py30 = True
  15.     from tkinter import *
  16.     import ttk
  17. elif version >= 0x03010000:
  18.     py31 = True
  19.     from tkinter import *
  20.     import tkinter.ttk as ttk
  21. else:
  22.     print ("""
  23.    You do not have a version of python supporting ttk widgets..
  24.    You need a version >= 2.6 to execute PAGE modules.
  25.    """)
  26.     sys.exit()
  27.  
  28. def vp_start_gui():
  29.     '''Starting point when module is the main routine.'''
  30.     global val, w, root
  31.     root = Tk()
  32.     root.title('Test_Form')
  33.     root.geometry('280x186+474+263')
  34.     w = Test_Form (root)
  35.     init()
  36.     root.mainloop()
  37.  
  38. w = None
  39. def create_Test_Form (root):
  40.     '''Starting point when module is imported by another program.'''
  41.     global w, w_win
  42.     if w: # So we have only one instance of window.
  43.         return
  44.     w = Toplevel (root)
  45.     w.title('Test_Form')
  46.     w.geometry('280x186+474+263')
  47.     w_win = Test_Form (w)
  48.     init()
  49.     return w_win
  50.  
  51. def destroy_Test_Form ():
  52.     global w
  53.     w.destroy()
  54.     w = None
  55.  
  56. def Button1Click(p1) :
  57.     sys.exit()
  58.  
  59. def init():
  60.     pass
  61.  
  62. class Test_Form:
  63.     def __init__(self, master=None):
  64.         # Set background of toplevel window to match
  65.         # current style
  66.         style = ttk.Style()
  67.         theme = style.theme_use()
  68.         default = style.lookup(theme, 'background')
  69.         master.configure(background=default)
  70.  
  71.         self.Button1 = Button (master)
  72.         self.Button1.place(relx=0.43,rely=0.38,height=27,width=49)
  73.         self.Button1.configure(activebackground="#f9f9f9")
  74.         self.Button1.configure(text='''Exit''')
  75.         self.Button1.bind('<Button-1>',Button1Click)
  76.  
  77. if __name__ == '__main__':
  78.     vp_start_gui()
  79.  
  80. #############################################
  81. # demos.py
  82. #! /usr/bin/env python
  83. # -*- python -*-
  84.  
  85. import sys
  86.  
  87. py2 = py30 = py31 = False
  88. version = sys.hexversion
  89. if version >= 0x020600F0 and version < 0x03000000 :
  90.     py2 = True    # Python 2.6 or 2.7
  91.     from Tkinter import *
  92.     import ttk
  93. elif version >= 0x03000000 and version < 0x03010000 :
  94.     py30 = True
  95.     from tkinter import *
  96.     import ttk
  97. elif version >= 0x03010000:
  98.     py31 = True
  99.     from tkinter import *
  100.     import tkinter.ttk as ttk
  101. else:
  102.     print ("""
  103.    You do not have a version of python supporting ttk widgets..
  104.    You need a version >= 2.6 to execute PAGE modules.
  105.    """)
  106.     sys.exit()
  107.  
  108. def vp_start_gui():
  109.     '''Starting point when module is the main routine.'''
  110.     global val, w, root
  111.     root = Tk()
  112.     root.title('Demos')
  113.     root.geometry('510x230+283+147')
  114.     set_Tk_var()
  115.     w = Demos (root)
  116.     init()
  117.     root.mainloop()
  118.  
  119. w = None
  120. def create_Demos (root):
  121.     '''Starting point when module is imported by another program.'''
  122.     global w, w_win
  123.     if w: # So we have only one instance of window.
  124.         return
  125.     w = Toplevel (root)
  126.     w.title('Demos')
  127.     w.geometry('510x230+283+147')
  128.     set_Tk_var()
  129.     w_win = Demos (w)
  130.     init()
  131.     return w_win
  132.  
  133. def destroy_Demos ():
  134.     global w
  135.     w.destroy()
  136.     w = None
  137.  
  138. def set_Tk_var():
  139.     # These are Tk variables used passed to Tkinter and must be
  140.     # defined before the widgets using them are created.
  141.     global rbc1
  142.     rbc1 = StringVar()
  143.  
  144.     global rbc2
  145.     rbc2 = StringVar()
  146.  
  147. def btnExitClicked(p1) :
  148.     sys.exit()
  149.  
  150. def btnNormalClicked(p1) :
  151.     print "Normal Button Clicked"
  152.  
  153. def btnSunkenClicked(p1) :
  154.     print "Sunken Button Clicked"
  155.  
  156. def init():
  157.     pass
  158.  
  159. class Demos:
  160.     def __init__(self, master=None):
  161.         # Set background of toplevel window to match
  162.         # current style
  163.         style = ttk.Style()
  164.         theme = style.theme_use()
  165.         default = style.lookup(theme, 'background')
  166.         master.configure(background=default)
  167.  
  168.         self.Frame1 = Frame (master)
  169.         self.Frame1.place(relx=0.02,rely=0.04,relheight=0.33,relwidth=0.97)
  170.         self.Frame1.configure(relief=GROOVE)
  171.         self.Frame1.configure(borderwidth="2")
  172.         self.Frame1.configure(relief="groove")
  173.  
  174.         self.Label1 = Label (self.Frame1)
  175.         self.Label1.place(relx=0.02,rely=0.13,height=19,width=51)
  176.         self.Label1.configure(activebackground="#f9f9f9")
  177.         self.Label1.configure(text='''Buttons''')
  178.  
  179.         self.Button1 = Button (self.Frame1)
  180.         self.Button1.place(relx=0.34,rely=0.4,height=27,width=69)
  181.         self.Button1.configure(activebackground="#f9f9f9")
  182.         self.Button1.configure(text='''Normal''')
  183.         self.Button1.bind('<Button-1>',btnNormalClicked)
  184.  
  185.         self.Button2 = Button (self.Frame1)
  186.         self.Button2.place(relx=0.61,rely=0.4,height=27,width=72)
  187.         self.Button2.configure(activebackground="#f9f9f9")
  188.         self.Button2.configure(text='''Sunken''')
  189.         self.Button2.bind('<Button-1>',btnSunkenClicked)
  190.  
  191.         self.Frame2 = Frame (master)
  192.         self.Frame2.place(relx=0.02,rely=0.39,relheight=0.33,relwidth=0.97)
  193.         self.Frame2.configure(relief=GROOVE)
  194.         self.Frame2.configure(borderwidth="2")
  195.         self.Frame2.configure(relief="groove")
  196.  
  197.         self.Radiobutton1 = Radiobutton (self.Frame2)
  198.         self.Radiobutton1.place(relx=0.32,rely=0.13,relheight=0.28
  199.                 ,relwidth=0.14)
  200.         self.Radiobutton1.configure(activebackground="#f9f9f9")
  201.         self.Radiobutton1.configure(text='''radio 1''')
  202.         self.Radiobutton1.configure(value="0")
  203.         self.Radiobutton1.configure(variable=rbc1)
  204.  
  205.         self.Radiobutton2 = Radiobutton (self.Frame2)
  206.         self.Radiobutton2.place(relx=0.32,rely=0.4,relheight=0.28,relwidth=0.14)
  207.  
  208.         self.Radiobutton2.configure(activebackground="#f9f9f9")
  209.         self.Radiobutton2.configure(text='''radio 2''')
  210.         self.Radiobutton2.configure(value="1")
  211.         self.Radiobutton2.configure(variable=rbc1)
  212.  
  213.         self.Radiobutton3 = Radiobutton (self.Frame2)
  214.         self.Radiobutton3.place(relx=0.61,rely=0.13,relheight=0.28
  215.                 ,relwidth=0.14)
  216.         self.Radiobutton3.configure(activebackground="#f9f9f9")
  217.         self.Radiobutton3.configure(text='''radio 3''')
  218.         self.Radiobutton3.configure(value="0")
  219.         self.Radiobutton3.configure(variable=rbc2)
  220.  
  221.         self.Radiobutton4 = Radiobutton (self.Frame2)
  222.         self.Radiobutton4.place(relx=0.61,rely=0.4,relheight=0.28,relwidth=0.14)
  223.  
  224.         self.Radiobutton4.configure(activebackground="#f9f9f9")
  225.         self.Radiobutton4.configure(text='''radio 4''')
  226.         self.Radiobutton4.configure(value="1")
  227.         self.Radiobutton4.configure(variable=rbc2)
  228.  
  229.         self.Label2 = Label (self.Frame2)
  230.         self.Label2.place(relx=0.02,rely=0.13,height=19,width=88)
  231.         self.Label2.configure(activebackground="#f9f9f9")
  232.         self.Label2.configure(text='''Radio Buttons''')
  233.  
  234.         self.Button3 = Button (master)
  235.         self.Button3.place(relx=0.45,rely=0.83,height=27,width=49)
  236.         self.Button3.configure(activebackground="#f9f9f9")
  237.         self.Button3.configure(text='''Exit''')
  238.         self.Button3.bind('<Button-1>',btnExitClicked)
  239.  
  240. if __name__ == '__main__':
  241.     vp_start_gui()
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement