- 论坛徽章:
- 0
|
回复 8# cdhigh
十分感谢你的回答,我现在还是刚刚入门级的菜鸟,你说的东西我只能说大概都明白,但是具体自己操作的时候,却还是出错,就拿你回答的第一点来举例,我是这样添加的:
———————————————————————————————————————————————————————————————————————————————
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from Tkinter import *
from tkFont import Font
from ttk import *
#Usage:showinfo/warning/error,askquestion/okcancel/yesno/retrycancel
from tkMessageBox import *
#Usage:f=tkFileDialog.askopenfilename(initialdir='E:/Python')
#import tkFileDialog
#import tkSimpleDialog
class Application_ui(Frame):
#这个类仅实现界面生成功能,具体事件处理代码在子类Application中。
def __init__(self,master=None):
Frame.__init__(self, master)
self.master.geometry('905x397')
self.createWidgets()
def createWidgets(self):
self.top = self.winfo_toplevel()
self.style = Style()
self.Text2Var = StringVar()
self.style.configure('TText2.TEntry', background='#C0C0C0')
self.Text2 = Entry(self.top, textvariable=self.Text2Var, style='TText2.TEntry')
self.Text2.place(relx=0.009, rely=0.181, relwidth=0.985, relheight=0.103)
self.style.configure('TCommand1.TButton', background='#FFFFFF', font=('Times New Roman',12,'bold'))
self.Command1 = Button(self.top, text='Reverse', command=self.rever, style='TCommand1.TButton')
self.Command1.place(relx=0.368, rely=0.846, relwidth=0.134, relheight=0.103)
self.Text4Var = StringVar()
self.style.configure('TText4.TEntry', background='#C0C0C0')
self.Text4 = Entry(self.top,textvariable=self.Text4Var,style='TText4.TEntry')
self.Text4.place(relx=0.009, rely=0.645, relwidth=0.985, relheight=0.123)
class Application(Application_ui):
#这个类实现具体的事件处理回调函数。界面生成代码在Application_ui中。
def __init__(self,master=None):
Application_ui.__init__(self, master)
def rever():
return self.Text4Var.set(self.Text2Var.get()[::-1])
if __name__ == "__main__":
top = Tk()
Application(top).mainloop()
try: top.destroy()
except: pass
————————————————————————————————————————————————————————————————————————————
但是程序跑起来后,报错了:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
TypeError: rever() takes no arguments (1 given)
由于自己对面向对象编程比较陌生,我不是很清楚改怎么去改!
还有就是其实我想做的并不是说在Text2中输入,然后在Text4中实时的显示出反转的结果,我想做的是在Text2中输入一个字符串,然后点击Button "Reverse",再将反转的结果输出到Text4中,其实很简单的功能,但是却总是出现各种问题,还请明示,十分感谢!
|
|