import tkinter.messagebox as messagebox
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import askdirectory
从Frame
派生一个Application
类,这是所有Widget的父容器:
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master.title('标题')
screenwidth = self.winfo_screenwidth()
screenheight = self.winfo_screenheight()
#设置界面宽度为530,高度为365像素,并且基于屏幕居中
width = 530
height = 365
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
self.master.geometry(size)
self.pack()
self.create_widgets()
在GUI中