(original) (raw)

''' Created on Sep 14, 2015 @author: alexw ''' # When aliasing tkinter as tk, you need to qualify any member of # tk you refer to. I learned this from Bryan Oakley. import tkinter as tk from tkinter import filedialog as tkfd, StringVar, messagebox, Entry from tkinter import constants, font import os import sys class MainWindow(tk.Frame): def __init__(self, master = None, **cnf): tk.Frame.__init__(self, master, cnf) self.master = master #Run my own init method self.init_window() def init_window(self): '''Initialize the window and position it on the screen''' #Set window size and position ScreenWidth = tk.Frame.winfo_screenwidth(self) ScreenHeight = tk.Frame.winfo_screenheight(self) xPos = ScreenWidth / 3 yPos = ScreenHeight / 3 #root seems to be a global variable pointing at the current instance of Tk root.geometry('800x300+%d+%d' % (xPos, yPos)) #set padding or widgets on row/col 0 will be flush against the window edge root.configure(padx=10, pady=10) #change the window title self.master.title("PDF Splitter") #Call method to put widgets on window: self.populate_window() def populate_window(self): '''Add widgets to this window''' # Add a button to the window self.btnSelectPDF = tk.Button(text = "Open", command=self.btnSelectPDFClick) self.btnSelectPDF.grid(row=0, column = 0) def btnSelectPDFClick(self): ''' Conjure the file open dialog to select file to split.. ''' tkfd.askopenfilename( title='Double click on a file', filetypes = [('Acrobat / PDF', '*.pdf')]) if __name__ == '__main__': root= tk.Tk() app = MainWindow(root) root.mainloop()