Hi,
I am supposed to make a GUI using Tkinter which has basic menubar options, a optionmenu and some textboxes. Here is the code.

from Tkinter import *
################ import basic libraries #################

import Tkinter
import Pmw
import tkMessageBox
import tkFont
from PIL import ImageTk,Image
from mmap import mmap,ACCESS_READ



def severity_pred_method():
   print("Block Duratione: %s\nLanes Blocked: %s\nLane Clearing Time: %s\nTruck Involved: %s" % (e1.get(), e2.get(), e3.get(),e4.get()))



class Printing:
    def __init__(self,text):
        self.text=text

    def __call__(self):
        print self.text

root = Tk()
Pmw.initialise(root)
root.title("Performance Measure")

background_image=ImageTk.PhotoImage(Image.open('wallpaper.jpg'))
background_label = Label(root, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
exitButton = Tkinter.Button(root, text = 'Exit', command =root.destroy)
exitButton.pack(side = 'bottom')

##############################
menuBar = Pmw.MenuBar(root, hull_relief = 'raised',hull_borderwidth = 1)
menuBar.pack(fill = 'x')
#self.menuBar = menuBar

########### adding some menubar buttons ###############

menuBar.addmenu('File','none')
menuBar.addmenuitem('File','command',command = Printing('Action: open'),label = 'open')
menuBar.addmenuitem('File', 'command',command = Printing('Action: close'),label = 'Close')
menuBar.addmenuitem('File','command', command = Printing('Action:save'),label = 'save')
menuBar.addmenuitem('File','command', command = Printing('Action:print'),label = 'print')
menuBar.addmenuitem('File', 'separator')
menuBar.addmenuitem('File', 'command',command = Printing('Action: exit'),label = 'Exit')
menuBar.addmenu('Edit','none')
menuBar.addmenuitem('Edit', 'command', command = Printing('Action: cut'),label = 'cut')
menuBar.addmenuitem('Edit', 'command',command = Printing('Action: copy'), label = 'copy')
menuBar.addmenuitem('Edit', 'command', command = Printing('Action: paste'), label = 'paste')
menuBar.addmenu('Help','none', side = 'right')
menuBar.addmenuitem('Help', 'command',command = Printing('Action: about'),label = 'About...')

exitButton = Tkinter.Button(root, text = 'Exit', command =root.destroy)
exitButton.pack(side = 'bottom')
############adding option Menu ###########################
variable = StringVar(root)
variable.set('select location name') # default value
w = OptionMenu(root, variable, '1','2','3')
w.pack()

button = Button(root, text="OK", command=Printing('everything:ok'))
button.pack()

###### Creating a frame ###########
textFrame = Frame(root)

######## Creating Label in the Frame ##########
entryLabel = Label(textFrame)
entryLabel["text"] = "Enter the Problem:"
entryLabel.pack(side=LEFT)

####### Create an Text Box in the Frame ########
entryWidget = Entry(textFrame)
entryWidget["width"] = 50
entryWidget.pack(side=LEFT)
textFrame.pack()
button = Button(root, text="Enter", command=Printing('ABCD'))
button.pack()     

##############Adding some more labels ########################
Label(root, text="Block Duration").grid(row=0)
Label(root, text="Lanes Blocked").grid(row=1)
Label(root, text="Lane clearing time in minutes").grid(row=2)
Label(root, text="Truck Involved").grid(row=3)


e1 = Entry(root)
e2 = Entry(root)
e3=Entry(root)
e4 = Entry(root)


e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=2,column=1)
e4.grid(row=3, column=1)

Button(root, text='Severity', command=severity_pred_method).grid(row=4, column=1, sticky=W, pady=4)

mainloop()

It seems that it sticks in infinite loop. Although when I run this in small snippets it works fine. Please help.
Thanks
Himanshu

It might be because you are mixing layout managers place() and pack(). Never a good idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.