AttributeError:class Frame没有属性'StringVar'

时间:2017-05-29 12:23:15

标签: python tkinter

所以我在下面有这个代码。我尝试了各种形式的如何去工作StringVar,但没有发生任何事情。这就是为什么一个转向你哦,stackoverflow之神。请告诉我如何实现它。我在Entry1中有一个输入,我需要将此输入转换为sql(由于它不重要而将其删除)并返回它的值并将其写入原始输入的Entry1 insted中。请大家呐喊我!

#!usr/bin/python
#-*- coding: utf-8 -*-

import os
import time
import mysql.connector
import getpass
import smtplib
from email.mime.text import MIMEText
global atado_kartya_input
global atvevo_kartya_input
from PIL import Image, ImageTk
#from Tkinter import Tk, Text, TOP, BOTH, X, N, LEFT
from Tkinter import * 
from Tkinter import Tk as tk
from ttk import Frame, Style, Entry, Label

class Example(Frame):
    def __init__(self, parent):

        Frame.__init__(self, parent)

        self.parent = parent
        self.initUI()
        self.addbutton()

    def addbutton(self):        
        b = Button( self, text= "Get!", width = 10, command= self.callback)
        b.pack()

    def callback(self): 
        #07561847   
        #tk()
        atvevoText = Frame.StringVar()
        atvevoText = atvevo(self.entry1.get()) #from the "atvevo" function it gets a name of a worker form an SQL statement
        self.entry1.delete(0, 'end')
        self.entry1.insert(0, atvevoText)
        #self.entry1 = Entry(self, textvariable = atvevoText )

        print(atvevoText)

    def initUI(self):
        self.parent.title("Pozi")
        self.pack(fill = BOTH, expand=True)

        frame1 = Frame(self)
        frame1.pack(fill=X)

        lbl1 = Label(frame1, text = "ĂtadĂł kártyája", width = 30)
        lbl1.pack(side = LEFT, padx=5, expand=True)

        self.entry1 = Entry(frame1)
        self.entry1.pack(side = LEFT, padx=5, expand=True)

        frame2 = Frame(self)
        frame2.pack(fill=X)

        lbl2 = Label(frame2, text = "ĂrvevĹ‘ kártyája", width = 30)
        lbl2.pack(side = LEFT, padx=5, expand=True)

        entry2 = Entry(frame2)
        entry2.pack(side = LEFT, padx=5, expand=True)

        frame3 = Frame(self)
        frame3.pack(fill=X)

        lbl3 = Label(frame3, text = "ĂrvevĹ‘ kártyája", width = 30)
        lbl3.pack(side = LEFT, padx=5, expand=True)

        entry3 = Entry(frame3)
        entry3.pack(side = LEFT, padx=5, expand=True)

        frame4 = Frame(self)
        frame4.pack(fill=BOTH, expand = True)

        lbl4 = Label(frame4, text = "Title", width = 30)
        lbl4.pack(side = LEFT, anchor=N, padx=5, pady=5)

        txt = Text(frame4)
        txt.pack(fill = BOTH, padx=5, pady=5, expand=True)      

         #Style().configure("TFrame", backgroung = "#333") # tframe háttérszinét beállítjuk90%  
def main():

    root = Tk()
    root.geometry("550x450+300+300") # width x heigth + x + y (on screen)
    app = Example(root)
    root.mainloop()  


if __name__ == '__main__':
    main()      

更新

我必须以这样的方式改变:

    def callback(self): 
        #07561847   
        #tk()
        atvevoText = StringVar()
        number = self.entry1.get()
        self.entry1.delete(0, 'end')
        #self.entry1.insert(0, atvevoText)
        self.entry1 = Entry(self, textvariable = atvevoText )
        atvevoText = atvevo(number)             
        print(atvevoText)

*有了它,我没有任何回复,也没有错误,也没有价值:( *

1 个答案:

答案 0 :(得分:1)

更改

Frame.StringVar()

StringVar()

由于StringVarTkinter内的一个类(未经过Google搜索测试)