Возникли проблемы с использованием TKinter в python. Медленно создавая то, что будет простой программой с одним основным окном и 4 вкладками (блокнотами), я столкнулся с проблемой определения того, как передать имя файла функции, которая в нем нуждается.
У меня есть одна кнопка, которая открывает диалоговое окно файла и позволяет пользователю выбрать файл и (надеюсь) получить имя файла. У меня есть еще одна настройка кнопки, которая (надеюсь) вызовет процесс с именем выбранного файла, переданным в качестве аргумента методу, вызываемому в команде. Прямо сейчас я могу вызвать диалоговое окно открытия файла и вывести имя файла на консоль, но я не могу понять, как передать это имя файла команде delineate (которая в конечном итоге вызовет другой скрипт с именем файла в качестве входных данных для этого сценарий). Я настроил его так, что при нажатии кнопки «Определить» в окне отображается «Очертание ....». Моя цель - иметь возможность отображать «Очертание X», где X — это имя открытого файла, и передавать это имя другому сценарию. Если я смогу довести его до точки, где правильно отображается «Очертание X», это означает, что имя файла было передано, и я думаю, что могу сделать все остальное...
Вот код:
from Tkinter import *
import ttk
import tkFileDialog
import tkMessageBox
import Tkconstants
class Unified_Tool(ttk.Frame):
# =============================================================================
# Main setup options
def __init__(self, isapp=True, name='unified_tool'):
ttk.Frame.__init__(self, name=name)
self.master.title("Unified Tool")
self.pack(expand=Y, fill=BOTH)
self.isapp = isapp
self._create_widgets()
file_name = StringVar()
def _create_widgets(self):
self._create_panels()
def _create_panels(self):
panel = Frame(self, name='panel')
panel.pack(side=TOP, fill=BOTH, expand=Y)
# create the notebook
nb = ttk.Notebook(panel, name='notebook_panel')
nb.pack(fill=BOTH, expand=Y, padx=2, pady=3)
self._create_ca_del_tab(nb)
#self._create_traversal_tab(nb)
#self._create_tot_tab(nb)
#self._create_zcc_tab(nb)
# =============================================================================
# Delineation tab
def load_file(self):
file_name = tkFileDialog.askopenfilename(filetypes=([('All files', '*.*'),
('Text files', '*.txt'),
('CSV files', '*.csv')]))
print file_name
# =============================================================================
# Delineation tab
def _create_ca_del_tab(self, nb):
# variable to store the filename
del_filename = StringVar()
# frame to hold content
frame = ttk.Frame(nb, name='ca_delineation')
# widgets to be displayed on 'Description' tab
msg = ["For delineating the catchment area of a point or collection of points. In "
"the file selection box to the left, select the input file containing the points "
"for catchment area delineation."]
lbl_intro = ttk.Label(frame, wraplength='4i', justify=LEFT, anchor=N,
text=''.join(msg))
# button for selecting the input file
btn_del_select_file = ttk.Button(frame, text="Browse", command=self.load_file, width=10)
# button for triggering the task
btn_del = ttk.Button(frame, text='Delineate!', underline=0,
command=lambda v=del_filename: self._delineate(del_filename))
# label that displays the input file name
lbl_del = ttk.Label(frame, textvariable=del_filename, name='delineate')
# position and set resize behaviour
lbl_intro.grid(row=0, column=0, columnspan=2, sticky='new', pady=5)
lbl_del.grid(row=1, column=1, pady=(2,4))
btn_del_select_file.grid(row=1, column=0, pady=(2,4))
btn_del.grid(row=2, column=0, pady=(2,4))
frame.rowconfigure(1, weight=1)
frame.columnconfigure((0,1), weight=1, uniform=1)
# add to notebook (underline = index for short-cut character)
nb.add(frame, text='CA Delineation', underline=0, padding=2)
def _delineate(self, v):
v.set('Delineating....')
self.update()
class method
. проверьте этот PDF-файл google.com.tr/ Почему вы пытаетесь усложнять? Система управления ядерной бомбой? - person dsgdfg   schedule 15.01.2016