使用Python在GUI中创建欢迎页面界面

时间:2017-10-03 19:58:30

标签: python tkinter

嘿,我在创建GUI欢迎页面界面时遇到了一些麻烦,并希望有人可以提供帮助。

GUI必须如下所示: enter image description here

框1必须是没有轮廓的整个界面的框架 方框2应该是一个文本框 框3应该是输入文本框(名称的字母数字字符串) 框4应该是输入文本框(密码的字母数字字符串) 方框5应该是一个带文本框的按钮,以便继续到下一页(仅当方框4中的密码正确时)。

到目前为止,我设法编写的是:

####### Welcome Page Interface med lille skærm #######

import tkinter
#import TkFileDialog
#import tkMessageBox

from tkinter import *

def main ():
    root = Tk()
    root.title("Welcome Page Interface")
    root.minsize(width = 1370, height = 700)
    root.maxsize(width = 1370, height = 700)

    button2 = Button(root, text = "Textbox", width = 150, height = 10)
    button2.pack(side = TOP, padx = 1, pady = 50 )
    button2.pack()

    button3 = Button(root, text = "Input textbox", width = 20, height = 2)
    button3.pack(side = TOP, padx = 10, pady = 100 )
    button3.pack()

    button4 = Button(root, text = "Input textbox #Password#", width = 30, height = 500)
    button4.pack(side = BOTTOM, padx = 10, pady = 140 )
    button4.pack()

    button5 = Button(root, text = "Continue to the next page", width = 30, height = 1)
    button5.pack(side = BOTTOM, padx = 10, pady= 110 )
    button5.pack()

    root.mainloop()

if __name__ == "__main__":
    main()


###############################


#from tkinter import *

#root = Tk()

#Label(root, text="First Name").grid(row=0, sticky=W, padx=4)
#Entry(root).grid(row=0, column=1, sticky=E, pady=4)

#Label(root, text="Last Name").grid(row=1, sticky=W, padx=4)
#Entry(root).grid(row=1, column=1, sticky=E, pady=4)

#Button(root, text="Submit").grid(row=3)

#root.mainloop()

###############################
#import tkinter
#import TkFileDialog
#import tkMessageBox

#from tkinter import *

#def main ():
#    root = Tk()
#    root.title("Welcome Page Interface")
#    root.minsize(width = 1370, height = 700)
#    root.maxsize(width = 1370, height = 700)

#    button2 = Button(root, text="Textbox", width=150, height=10)
#        button2.pack(side = TOP, padx = 1, pady = 50 )
#        button2.pack()



#    Label(root, text="").grid(row=0, sticky=W, padx=4)

#    Label(root, text="B").grid(row=4, sticky=E, padx=8)
#    Entry(root).grid(row=0, column=3, sticky=E, pady=5)

#    Label(root, text="H").grid(row=4, sticky=W, padx=5)
#    Entry(root).grid(row=0, column=2, sticky=E, pady=5)

##########


#    Label(root, text="First Name").grid(row=0, sticky=W, padx=4)
#    Entry(root).grid(row=0, column=1, sticky=E, pady=4)

#    Label(root, text="Last Name").grid(row=7, sticky=W, padx=5)
#    Entry(root).grid(row=0, column=0, sticky=E, pady=4)

#    Button(root, text="Submit").grid(row=3)

#    root.mainloop()


#if __name__ == "__main__":
#    main()

但是我的按钮一直在阻碍对方,我无法让它工作。

希望有人可以提供帮助。

如果可以在Python 2.7.12中使用,那么我正在使用Python 3.6.2。

提前致谢

1 个答案:

答案 0 :(得分:0)

  • 按钮的height参数是文本行,而不是像素。 500是完全不合理的。
  • pady参数以像素为顶部和底部。所以pady=140将小部件放在280像素高的字段的中心。
  • 选择一个侧面并坚持使用所有小部件。 TOP是默认值。
  • 每个小部件只需要调用pack一次。
  • 使用Entry小部件从用户处获取文本。
  • 不要使用通配符导入。

-

import tkinter as tk

def main ():
    root = tk.Tk()
    root.title("Welcome Page Interface")
    root.minsize(width = 1370, height = 700)
    root.maxsize(width = 1370, height = 700)

    button2 = tk.Label(root, text = "Textbox", width = 150, height = 10, relief=tk.RAISED)
    button2.pack(padx = 1, pady = 50 )

    username_frame = tk.Frame(root)
    label = tk.Label(username_frame, text="Username")
    label.pack(side=tk.LEFT)
    button3 = tk.Entry(username_frame, width = 20)
    button3.pack(side=tk.LEFT)
    username_frame.pack(padx = 10, pady = 50 )

    button4 = tk.Entry(root, width = 30)
    button4.pack(padx = 10, pady = 20 )

    button5 = tk.Button(root, text = "Continue to the next page", width = 30, height = 1)
    button5.pack(padx = 10, pady= 20 )

    root.mainloop()

if __name__ == "__main__":
    main()