我正在尝试创建(text1)条目以获取打开的文件路径 我的意思是当我打开一个文件时,它会显示条目上的文件路径(文本框) 附言:对不起,这个坏榜样和英语
“Python”
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showerror
from tkinter import ttk
这是我的课
class SchoolProjict(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side = "top", fill = "both", expand = True)
container.grid_rowconfigure(0, weight = 1)
container.grid_columnconfigure(0, weight = 1)
self.frames = {}
for F in (StartPage, PageOne, SetingPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row = 0, column = 0, sticky = "nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
打开此按钮可从条目测试打印
def printingstuff(var1):
print (var1)
这是打开一个文件,我希望它改变条目显示文件路径
def load_file():
fname = askopenfilename(filetypes=(("Excel file", "*.xls"),
("HTML files", "*.html;*.htm"),
("All files", "*.*") ))
if fname:
try:
print(fname)
return
except: # <- naked except is a bad idea
showerror("Open Source File", "Failed to read file\n'%s'" % fname)
return
这是节目的框架
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
lablel = tk.Label(self, text = "Start Page")
lablel.pack(pady = 10, padx = 10)
button1 = tk.Button(self, text = "Main Menu", command = lambda: controller.show_frame(PageOne))
button1.pack()
button2 = tk.Button(self, text = "Siting", command = lambda: controller.show_frame(SetingPage))
button2.pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
lablel = tk.Label(self, text = "Main Menu")
lablel.pack(pady = 10, padx = 10)
button1 = tk.Button(self, text = "Start Page", command = lambda: controller.show_frame(StartPage))
button1.pack()
button2 = tk.Button(self, text = "Siting", command = lambda: controller.show_frame(SetingPage))
button2.pack()
class SetingPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
lablel = tk.Label(self, text = "Siting Page")
lablel.pack(pady = 10, padx = 10)
text1 = ttk.Entry(self)
text1.pack()
text1.focus()
button1 = tk.Button(self, text = "Print from Entry", command = lambda: printingstuff(text1.get()))
button1.pack()
button2 = tk.Button(self, text="open File", command= load_file, width=10)
button2.pack()
button3 = tk.Button(self, text = "Main Menu", command = lambda: controller.show_frame(PageOne))
button3.pack()
button4 = tk.Button(self, text = "Start Page", command = lambda: controller.show_frame(StartPage))
button4.pack()
主回路
app = SchoolProjict()
app.mainloop()
'''' 如果说不通的话,我很抱歉
相关问题 更多 >
编程相关推荐