wxpython,有两个文本框,三个按钮控件,按下按钮便可以将文本框一中的内容复制到文本二中
这三个按钮的功能都是一样的,函数的写法可以相同,函数名不同便可。最好是将文本框一中的内容取出保存在放到文本二中。(给出完整代码,不要问为什么三个按钮,分数好商量)...
这三个按钮的功能都是一样的,函数的写法可以相同,函数名不同便可。最好是将文本框一中的内容取出保存在放到文本二中。(给出完整代码,不要问为什么三个按钮,分数好商量)
展开
2个回答
展开全部
#coding=utf-8
import wx
import wx.richtext as rt
class CopyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
#用于点击按钮时保存
self.msg = ""
self.initGUI()
def initGUI(self):
self.__create_componts()
self.__set_properties()
self.__do_layout()
def __create_componts(self):
self.leftTxt = rt.RichTextCtrl(self, style=wx.TE_MULTILINE)
self.rightTxt = rt.RichTextCtrl(self, style=wx.TE_MULTILINE)
self.funcBtn1 = wx.Button(self, label="Function1")
self.funcBtn2 = wx.Button(self, label="Function2")
self.funcBtn3 = wx.Button(self, label="Function3")
self.Bind(wx.EVT_BUTTON, self.onFunction1Click, self.funcBtn1)
self.Bind(wx.EVT_BUTTON, self.onFunction2Click, self.funcBtn2)
self.Bind(wx.EVT_BUTTON, self.onFunction3Click, self.funcBtn3)
def onFunction1Click(self, evt):
self.left2right()
def onFunction2Click(self, evt):
self.left2right()
def onFunction3Click(self, evt):
self.left2right()
def left2right(self):
msg = self.leftTxt.GetValue()
self.msg = msg
self.rightTxt.SetValue(msg)
def __set_properties(self):
pass
def __do_layout(self):
mainSizer = wx.BoxSizer(wx.HORIZONTAL)
self.SetSizer(mainSizer)
leftSizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, u"Left Txt"), wx.VERTICAL)
buttonSizer = wx.BoxSizer(wx.VERTICAL)
rightSizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, u"Right Txt"), wx.VERTICAL)
mainSizer.Add(leftSizer, 2, wx.EXPAND | wx.ALL, 10)
mainSizer.Add(buttonSizer, 1, wx.EXPAND | wx.ALL, 10)
mainSizer.Add(rightSizer, 2, wx.EXPAND | wx.ALL, 10)
#左侧文本框
leftSizer.Add(self.leftTxt, 1, wx.EXPAND | wx.ALL, 10)
#中间按钮
buttonSizer.Add(self.funcBtn1, 0, wx.ALL, 10)
buttonSizer.Add(self.funcBtn2, 0, wx.ALL, 10)
buttonSizer.Add(self.funcBtn3, 0, wx.ALL, 10)
#右侧文本框
rightSizer.Add(self.rightTxt, 1, wx.EXPAND | wx.ALL, 10)
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, size=(600, 400))
self.Center()
CopyPanel(self)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
就这样咯,靠,审批耽误哥时间。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#python33
from tkinter import *
# 按钮囘调函数
def callbtn1():
txt2.delete(0.0, END)
txt2.insert(END,str(txt1.get(0.0, END)))
def callbtn2():
txt2.delete(0.0, END)
txt2.insert(END,str(txt1.get(0.0, END)))
def callbtn3():
txt2.delete(0.0, END)
txt2.insert(END,str(txt1.get(0.0, END)))
root = Tk()
# 创建三个button
btn1 = Button(root, width=20, height=2, text='1', command=callbtn1)
btn2 = Button(root, width=20, height=2, text='2', command=callbtn2)
btn3 = Button(root, width=20, height=2, text='3', command=callbtn3)
# 创建2个文本框
txt1 = Text(root)
txt2 = Text(root)
# 布局
btn1.grid(row = 0, column = 0, sticky=N)
btn2.grid(row = 1, column = 0, sticky=N)
btn3.grid(row = 2, column = 0, sticky=N)
txt1.grid(row = 0, column = 1)
txt2.grid(row = 1, column = 1)
root.mainloop()
新手菜只会用tk~~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询