Python Tkinter输入框
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python Tkinter输入框,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2112字,纯文字阅读大概需要4分钟。
内容图文
![Python Tkinter输入框](/upload/InfoBanner/zyjiaocheng/680/6fb1fe3dc5334b668fcb8d2b100f4d99.jpg)
美好的一天.
我正在尝试创建自己的输入框供我的项目使用.
基本上我想做的是运行我的主窗体,该窗体将称为第二个窗体.用户将在第二秒提供一些数据,并且当按下第二秒的“确定/关闭”按钮以将数据传递回第一秒时.功能与输入框类似.
这是我创建的,但是是python的新手,我不确定我要去哪里错误/也无法迅速找出何时放回收益.
My Class is here
import tkinter as tk
class MainWindow():
def __init__(self, parent):
top = self.top = tk.Toplevel(parent)
self.myLabel = tk.Label(top, text='Enter a Grouping Name')
self.myLabel.pack()
self.myEntryBox = tk.Entry(top)
self.myEntryBox.focus_set()
self.myEntryBox.pack()
self.mySubmitButton = tk.Button(top, text='OK', command=self.DestWin)
self.mySubmitButton.pack()
def DestWin(self):
self.top.destroy()
The method to call it is here
abc=configurator.MainWindow(root)
解决方法:
不确定要实现的目标,但是如果要从一个窗口获取值到另一个窗口,则可以在下面找到基于代码的扩展示例.
import tkinter as tk
class MainWindow():
def __init__(self, parent):
top = self.top = tk.Toplevel(parent)
self.myLabel = tk.Label(top, text='Enter a Grouping Name')
self.myLabel.pack()
self.myEntryBox = tk.Entry(top)
self.myEntryBox.focus_set()
self.myEntryBox.pack()
self.mySubmitButton = tk.Button(top, text='OK', command=self.DestWin)
self.mySubmitButton.pack()
def DestWin(self):
# call callback function setting value in MyFrame
self.callback(self.myEntryBox.get())
self.top.destroy()
def set_callback(self, a_func):
self.callback = a_func
class MyFrame(tk.Frame):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
self.pack()
self.myLabel1 = tk.Label(parent, text='Click OK to enter the group name')
self.myLabel1.pack()
self.mySubmitButton1 = tk.Button(parent, text='OK', command=self.get_group_name)
self.mySubmitButton1.pack()
def get_group_name(self):
mw = MainWindow(None)
# provide callback to MainWindow so that it can return results to MyFrame
mw.set_callback(self.set_label)
def set_label(self, astr = ''):
self.myLabel1['text'] = astr
root = tk.Tk()
mf = MyFrame(root)
root.mainloop()
屏幕截图:
按下OK时,右侧窗口中的文本将显示在左侧窗口中.这是通过回调实现的. MainWindow具有回调函数,当您按OK时,将执行它.回调是MyFrame中的set_label.
希望这可以帮助.
内容总结
以上是互联网集市为您收集整理的Python Tkinter输入框全部内容,希望文章能够帮你解决Python Tkinter输入框所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。