0
我想知道为什么默认文本不会出现在输入字段。在同一屏幕上一切正常。问题是当我从另一个文件调用函数时。我有这个菜单,调用函数,一切显示正常,但不是默认的文本与内foldersThis导入文件的主菜单文件是我的代码:为什么默认文本条目Python Tk在函数中不起作用?
__author__ = 'jordiponsisala'
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import*
def mnuArticles():
def provaD():
print('Imprimiendo algo')
print(entDescripcio.get())
root = Tk()
root.resizable(0,0)
notebook = ttk.Notebook(root)
notebook.pack(fill=BOTH, expand=True,)
notebook.pressed_index = None
notebook.master.title("Manteniment d'Articles")
notebook.master.geometry('900x650+0+100')
container1 = Frame(notebook,bg='grey')
container2 = Frame(notebook)
notebook.add(container1, text='Article')
botoImprimir = tk.Button
botoImprimir(container1,text='Provando',highlightbackground='grey'
,command=provaD).place(x=650,y=450)
tk.Label(container1,text='Codig',bg='grey').place(x=45,y=5)
tk.Label(container1,text='Descripció',bg='grey').place(x=200,y=5)
entArticle = StringVar()
entDescripcio = StringVar()
entDescripcio.set('the default text that does not appear')
txtArticle = Entry(container1,textvariable=entArticle
,width=10,highlightthickness='0').place(x=100,y=0)
txtDescripcio = Entry(container1,textvariable= entDescripcio
,width=50,highlightthickness='0').place(x=280,y=0)
notebook.add(container2, text='Preu')
root.mainloop()
这是主文件的代码。 要测试你需要创建一个名为manteniment 一个文件夹,并在一开始就把一个空文件__init__.py里面用下划线并结束
from tkinter import *
from manteniment.articles import *
ventana = Tk()
ventana.geometry ('500x500+0+0')
ventana.title ('Benvinguts')
lblVentana = Label(text='Grub article').pack()
barraMenu = Menu (ventana)
mnuArchivo = Menu (barraMenu)
mnuTpv = Menu (barraMenu)
mnuLListats = (barraMenu)
mnuArchivo.add_command (label='Articles',command=mnuArticles) #I call the function here
barraMenu.add_cascade(label = 'Mantenimiento',menu =mnuArchivo)
barraMenu.add_cascade(label = 'TPV', menu = mnuTpv)
ventana.config(menu = barraMenu)
ventana.mainloop()
这是最好的解决方案,我学到了很好的一课。 我喜欢python和tkinter哈哈。 – 2014-09-26 20:54:49