[Python] 纯文本查看 复制代码
from tkinter.constants import NO
from tkinter import Label, filedialog, Button, Frame
from tkinter import Entry, StringVar, messagebox, Tk, constants, mainloop
import pandas as pd
from tkinter.scrolledtext import *
class MainWindow():
def __init__(self) -> None:
button_relief = 'RAISED' # 用于设置图标效果,这里设为凸起
self.root = Tk()
self.root.title("pdf data killer")
x = (self.root.winfo_screenwidth() - self.root.winfo_reqwidth()) // 4
y = (self.root.winfo_screenheight() - self.root.winfo_reqheight()) // 4
# 窗口位置 几何
self.root.geometry(f"580x520+{x}+{y}")
frame = Frame(self.root)
frame.pack(padx=2, pady=2, ipadx=1)
bg = "#DCDCDC"
btn_open = Button(frame, text="open", width=5, height=1, command=self.open_pdf,).grid(
row=0, column=0, padx=5, pady=5, sticky='W', columnspan=1)
label_page = Label(frame, text="page number:", width=12, height=1, bg=bg).grid(
row=0, column=2, padx=5, pady=5, sticky='W')
pages = StringVar()
page_input = Entry(frame, bd=1, textvariable=pages).grid(
row=0, column=3, padx=5, pady=5, sticky='W')
btn_save = Button(frame, text="save", width=5, height=1, command=self.sava_data).grid(
row=0, column=5, padx=5, pady=5, sticky='W')
textPad = ScrolledText(self.root, width=50, height=40)
textPad.insert(constants.END, chars=str(self.data_example()))
textPad.pack(expand='YES', fill='both')
def open_pdf(self):
self.root.withdraw()
self.Filepath = filedialog.askopenfilename(
title='Please choose a file', initialdir='/', filetypes=[('Pdf file', '*.pdf')])
print(self.Filepath)
return self.Filepath
# 保存文件
def sava_data(self):
messagebox.showinfo('提示', '保存成功')
def data_example(self):
data = {'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada'],
'year': [2000, 2001, 2002, 2003, 2004, ],
'pop': [12313, 1213, 3131, 1213, 121321]}
data_frame = pd.DataFrame(data)
data_frame.index += 1
return data_frame
if __name__ == "__main__":
main = MainWindow()
mainloop()