Найти - Пользователи
Полная версия: Вывод текстового файла в текстовый фрейм
Начало » Python для новичков » Вывод текстового файла в текстовый фрейм
1
Artemkadollar
Не могу понять как вывести файл во фрейм. Скрин программы вкладываю.
 from tkinter import*
from tkinter import ttk
from tkinter.filedialog import*
import sys  
def Quit(ev):
    global root
    root.destroy()
def OpenFile(ev):
    name = askopenfilename(filetypes =(("Текст", "*.txt"),("All Files","*.*")),title = "Открытие файла...")
    print(name)
    try:
        with open(name,'r') as UseFile:
            textFrame=print(UseFile.read())
    except:
        print("No file exists")
root=Tk()
textFrame = Frame(root,height = 10, width = 60)
textFrame.pack(side = 'top', expand = False)
textbox = Text(textFrame, font='Arial 14', wrap='word')
textbox.pack(side = 'left',expand = False)
label = ttk.Label(root,width=650,text ="                                                                             Откройте файл, который хотите просмотреть",foreground="black",background="light blue",font=("Helvetica", 16))
label.pack()
panelFrame=Frame(root,height=100,bg='gray')
panelFrame.pack(side='top',fill='x',expand=True)
root["bg"] = "grey"
root.state("zoomed")
label = ttk.Label(root,width=600,text ="",foreground="black",background="light blue",font=("Helvetica", 16))
label.pack()
Title = root.title( "Просмотрщик документов")
loadBtn=Button(panelFrame,text='Завантаження')
quitBtn=Button(panelFrame,text='Вихід')
loadBtn.bind("<Button-1>",OpenFile)
quitBtn.bind("<Button-1>",Quit)
loadBtn.place(x=10,y=10,width=90,height=90)
quitBtn.place(x=1270,y=10,width=90,height=90)
root.mainloop()
PEHDOM
вот это что?
 textFrame=print(UseFile.read())
рекумендую вам сделать пару шагов назад и еще раз изучить теорию, налицо непонимание как работает пайтон вообще, и ткинтер с ООП в частности.

вот так оно работает:
 textbox.insert(END,UseFile.read())

ЗЫ часть надписей на русском а подписи к кнопкам на украинском вызывает желание вырвать себе глаза, делайте все на одном языке.
Artemkadollar
Спасибо огромное!)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB