Python状态栏

时间:2016-05-23 01:33:51

标签: python user-interface tkinter

我在程序底部添加状态栏时遇到问题。当我执行status.pack()时,它给了我这个错误:_tkinter.TclError:不能在里面使用几何管理器网格。已经有包管理的奴隶。在我的 ( def init (self):)如果我删除(self.grid(sticky = W + E + N + S)然后弹出窗口然后状态栏在窗口上,但是该计划的其余部分不在那里。我想知道是否有人就如何解决这个问题提供了一些见解

from tkinter.constants import END
from tkinter import ttk
from tkinter import *
from tkinter import font
from tkinter import messagebox
import tkinter as tk
import turtle 
import random
from tkinter import filedialog
from PIL import Image

class App(Frame):

*************** ************************************************** ************************************************** ************************************************** ***************** 8888

'''The code below Creates a Menu Bar across the top of the window '''    
App = Tk()
menu = Menu (App)
App.config(menu = menu)  
'''Lines 20 - 22 are basic setup for drop down meun box at the top of the page.'''


fileMenu = Menu(menu, tearoff = 0)
fileMenu.add_command(label = "New Project", command = turtle)
fileMenu.add_command(label = "Open", command = turtle)
fileMenu.add_command(label = "Save", command = turtle)
fileMenu.add_command(label = "Save as", command = turtle)
fileMenu.add_command(label = "Close", command = turtle)
menu.add_cascade(label = "File", menu = fileMenu)

fileMenu.add_separator() 
'''This bit of code adds a separator between the buttons on the drop down menu.'''
fileMenu.add_command(label = "Exit", command = App.quit)

editMenu = Menu(menu, tearoff = 0)
editMenu.add_command(label = "Cut", command = turtle)
editMenu.add_command(label = "Copy", command = turtle)
editMenu.add_command(label = "Paste", command = turtle)
editMenu.add_command(label = "Delete", command = turtle)
editMenu.add_command(label = "Select All", command = turtle)
menu.add_cascade(label = "Edit", menu = editMenu)

helpMenu = Menu(menu, tearoff = 0)
helpMenu.add_command(label = "Help Index", command = turtle)
helpMenu.add_command(label = "About", command = turtle)
menu.add_cascade(label = "Help", menu = helpMenu)

*************** ************************************************** ************************************************** ************************************************** *********

''' The code below creates a Status Bar Across the bottom of the page. '''

status = Label(App, text = "This is a status bar...", bd = 1, relief = SUNKEN, anchor = W)
status.pack()

*************** ************************************************** ************************************************** ************************************************** ********

def __init__(self):
    '''Sets up the window and widgets.'''
    Frame.__init__(self, bg = "white" ) #this sets the background color of the window.
    self.master.title("Auto Body Buddy Estimator")  #this is the title of the screen
    self.master.geometry("600x600") #this is the specs for the window size
    self.master.resizable(0, 0)     #this makes the window none resizable
    self.master.columnconfigure(0, weight = 1)
    self.master.rowconfigure(0, weight = 1)
    self.grid(sticky = W+E+N+S)

    #!/usr/bin/python

    '''import cgi, os
    import cgitb; cgitb.enable()

    form = cgi.FieldStorage()

    # Get filename here.
    fileitem = form['filename']

    # Test if the file was uploaded
    if fileitem.filename:
        # strip leading path from file name to avoid 
        # directory traversal attacks
        fn = os.path.basename(fileitem.filename)
        open('/tmp/' + fn, 'wb').write(fileitem.file.read())

        message = ('The file "' + fn + '" was uploaded successfully')

    else:
        message = 'No file was uploaded'

        print """\
        Content-Type: text/html\n
        <html>
        <body>
           <p>%s</p>
        </body>
        </html>
        """ % (message,) '''

*************** ************************************************** ************************************************** ********************

    ''' Creates the nested frame for the Data pane for the image '''
    self._dataPane1 = Frame(self)#, bg = "orange")
    self._dataPane1.grid(row = 0, column = 0)
    self._pictureImage = PhotoImage(file = "../logo.gif")
    self._imageLabel = Label(self._dataPane1, image = self._pictureImage)
    self._imageLabel.grid(row = 0, column= 0) 

*************** ************************************************** ************************************************** ******************

    ''' Creates the nested frame for the Data pane'''
    self._dataPaneEntryInfo = Frame(self, bg = "white")
    self._dataPaneEntryInfo.grid(row = 1, column = 0)

    ''' Label and field for First Name '''
    self._firstNameLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "First Name ")
    self._firstNameLabel.grid(row = 0, column = 0)
    self._firstNameVar = DoubleVar()
    self._firstNameEntry = Entry(self._dataPaneEntryInfo, textvariable = self._firstNameVar)
    self._firstNameEntry.grid(row = 0, column = 1)

    ''' Label and field for Last Name '''
    self._LastNameLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "Last Name ")
    self._LastNameLabel.grid(row = 1, column = 0)
    self._LastNameVar = DoubleVar()
    self._LastNameEntry = Entry(self._dataPaneEntryInfo, textvariable = self._LastNameVar)
    self._LastNameEntry.grid(row = 1, column = 1)

    ''' Label and field for Phone Number '''
    self._phoneNumberLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "Phone Number ")
    self._phoneNumberLabel.grid(row = 2, column = 0)
    self._phoneNumberVar = DoubleVar()
    self._phoneNumberEntry = Entry(self._dataPaneEntryInfo, textvariable = self._phoneNumberVar)
    self._phoneNumberEntry.grid(row = 2, column = 1)

    ''' Label and field for Email '''
    self._EmailLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "Email Address ")
    self._EmailLabel.grid(row = 3, column = 0)
    self._EmailVar = DoubleVar()
    self._EmailEntry = Entry(self._dataPaneEntryInfo, textvariable = self._EmailVar)
    self._EmailEntry.grid(row = 3, column = 1)

    ''' Label and field for Address '''
    self._addressLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "Address \n (OPITIONAL) ")
    self._addressLabel.grid(row = 4, column = 0)
    self._addressVar = DoubleVar()
    self._addressEntry = Entry(self._dataPaneEntryInfo, textvariable = self._addressVar)
    self._addressEntry.grid(row = 4, column = 1)

*************** ************************************************** ************************************************** ******************

    ''' Label and field for Year of the Car '''
    self._yearLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "Year ")
    self._yearLabel.grid(row = 0, column = 2)
    self._yearVar = DoubleVar()
    self._yearEntry = Entry(self._dataPaneEntryInfo, textvariable = self._yearVar)
    self._yearEntry.grid(row = 0, column = 3)

    ''' Label and field for Make of the Car '''
    self._makeLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "Make ")
    self._makeLabel.grid(row = 1, column = 2)
    self._makeVar = DoubleVar()
    self._makeEntry = Entry(self._dataPaneEntryInfo, textvariable = self._makeVar)
    self._makeEntry.grid(row = 1, column = 3)

    ''' Label and field for Model of the Car '''
    self._modelLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "Model ")
    self._modelLabel.grid(row = 2, column = 2)
    self._modelVar = DoubleVar()
    self._modelEntry = Entry(self._dataPaneEntryInfo, textvariable = self._modelVar)
    self._modelEntry.grid(row = 2, column = 3)

    ''' Label and field for Package of the Car '''
    self._packageLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "Package ")
    self._packageLabel.grid(row = 3, column = 2)
    self._packageVar = DoubleVar()
    self._packageEntry = Entry(self._dataPaneEntryInfo, textvariable = self._packageVar)
    self._packageEntry.grid(row = 3, column = 3)

    ''' Label and field for VIN # of the Car '''
    self._vinLabel = Label(self._dataPaneEntryInfo, bg = "white", text = "VIN # ")
    self._vinLabel.grid(row = 4, column = 2)
    self._vinVar = DoubleVar()
    self._vinEntry = Entry(self._dataPaneEntryInfo, textvariable = self._vinVar)
    self._vinEntry.grid(row = 4, column = 3)

*************** ************************************************** ************************************************** ************************************************** *

    ''' Creates the nested frame for the Data pane'''
    self._dataPaneComment = Frame(self, bg = "black")
    self._dataPaneComment.grid(row = 2, column = 0)

    '''# Label and info field for Comment Box .'''
    self._text = "Enter text here. "
    self._outputArea = Text(self._dataPaneComment, width = 50, height = 10, wrap = WORD)
    self._outputArea.grid(row = 0, column = 0, columnspan = 2)

*************** ************************************************** ************************************************** ************************************************** ****

    ''' Creates the nested frame for the Button pane for the Submit'''
    self._buttonPane = Frame(self) #this creates a box for the buttons to be placed in one area.
    self._buttonPane.grid(row = 3, column = 0)#this gives the button pane a position in the GUI

    ''' Black and White button '''
    self._button1 = Button(self._buttonPane, text = "SUBMIT", command = self._NameEntry)#This creates the button.
    self._button1.grid(row = 0, column = 0) #This gives the button a position in the GUI.

*************** ************************************************** ************************************************** ************************************************** ***

def _NameEntry(self):
    open("Results.txt", "w").close()

    first = self._firstNameEntry.get()
    last = self._LastNameEntry.get()
    phone = self._phoneNumberEntry.get()
    email = self._EmailEntry.get()
    address = self._addressEntry.get()
    year = self._yearEntry.get()
    make = self._makeEntry.get()
    model = self._modelEntry.get()
    package = self._packageEntry.get()
    vin = self._vinEntry.get()


    with open("../" + first + " " + last + ".txt", "a") as the_file:
        the_file.write("First Name: " + first + "\n" "Last Name: " + last + "\n" "Phone Number: " + phone + "\n" "Email: " + email + "\n" 
                       "Address: " + address + "\n" "Year: " + year + "\n" "Make: " + make + "\n" "Model: " + model + "\n" 
                       "Package: " + package + "\n" "Vin: " + vin + "\n")

    '''open("Results.txt", "w").close()
    last = self._LastNameEntry.get()
    with open("../Results.txt", "a") as the_file:
        the_file.write("Last Name: " + last)'''    

    '''first = self._firstNameEntry.get()   
    name = open("Results.txt", "w")
    name.write("First Name: ".insert(first))
    name.close()'''


def main():
'''Instantiate and pop up the window.'''

App().mainloop()
if __name__ == '__main__':
main()

我完全确定如何使用此代码上传gif文件。

1 个答案:

答案 0 :(得分:3)

错误消息告诉您错误。如果您已经在窗口小部件中使用了一个几何管理器,则无法使用另一个。

e.g。 - 您不能在框架内同时使用包和网格。你必须使用其中一个。

您可以制作另一个小部件,然后在此小部件中使用单独的几何管理器,但您必须使用原始管理器将其放置在主小部件中。