我试图输入(text1)以获得我打开显示的文件路径 我的意思是我打开了一个文件,它向我显示了条目(文本框)上的文件路径 ps:对不起,这个错误的例子和英语
''''python
acomber@mail:~/Documents/projects/modem/serial/gdbplay$ ls
main.cpp main.o Makefile serial
acomber@mail:~/Documents/projects/modem/serial/gdbplay$ make serial
g++ -Wall -Werror -ggdb3 -std=c++17 -pedantic -c main.cpp
g++ -o serial -Wall -Werror -ggdb3 -std=c++17 -pedantic main.o -L/usr/lib -lstdc++fs
acomber@mail:~/Documents/projects/modem/serial/gdbplay$ sudo ./serial
[sudo] password for acomber:
AT
No. found modems: 1
/dev/ttyACM0->
Operation took 8643 milliseconds
acomber@mail:~/Documents/projects/modem/serial/gdbplay$
这是我的怪胎课程
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()
'''' 抱歉,如果没有任何意义
答案 0 :(得分:0)
class SetingPage(tk.Frame):
def __init__(self, parent, controller):
...
self.text1 = tk.Entry(self) #<== i want to show the path of the file i am going to open Here after i select it from openfile
self.text1.grid(row = 2, column = 0)
self.text1.focus()
button1 = tk.Button(self, text = "print text1", command = lambda: printingstuff(self.text1.get()))
...