Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用按钮在python';斯特金特酒店_Python_User Interface_Tkinter - Fatal编程技术网

使用按钮在python';斯特金特酒店

使用按钮在python';斯特金特酒店,python,user-interface,tkinter,Python,User Interface,Tkinter,目标:单击加号按钮,输入框中将显示加号 我这里有一个非常简单的代码: basic=tk.Tk() basic_label=tk.Label('Welcome to Basic Math section. \n \n Note: Please enter white spaces between objects, \n e.g. 5 + 6 \n NOT 5+6') entry=tk.Entry() userInput=str(entry.get()) input1, op, input2=Use

目标:单击加号按钮,输入框中将显示加号 我这里有一个非常简单的代码:

basic=tk.Tk()
basic_label=tk.Label('Welcome to Basic Math section. \n \n Note: Please enter white spaces between objects, \n e.g. 5 + 6 \n NOT 5+6')
entry=tk.Entry()
userInput=str(entry.get())
input1, op, input2=UserInput.split(' ')

#casting inputs
input1=int(input1)
input2=int(input2)
plus=tk.Button(text='+', command=??)

我应该在命令中输入什么?

试试这个。我已经修复了您的GUI,并注释掉了一些错误的代码

import tkinter as tk
basic=tk.Tk()
basic_label=tk.Label(basic,text='Welcome to Basic Math section. \n \n Note: Please enter white spaces between objects, \n e.g. 5 + 6 \n NOT 5+6')
basic_label.grid()
entry=tk.Entry(basic)
entry.grid()
userInput=str(entry.get())
#input1, op, input2=userInput.split(' ')

#casting inputs
#input1=int(input1)
#input2=int(input2)
plus=tk.Button(basic,text='+',command=lambda:entry.insert(tk.END,"+"))
plus.grid()
basic.mainloop ()

从您的代码来看,您所做的研究似乎还不够

您需要从如何创建小部件以及如何使用与其相关的功能的基础知识开始

查看此链接:

让我举一个简单的例子:

这是创建标签的代码:

basic_label=tk.Label('Welcome to Basic Math section...')
首先,这甚至不能正确设置标签的文本,更不用说在框架上显示了

以下是构建标签小部件的方法:

labelName = tk.Label(root, text = '' , 'any other options')
labelName.grid(row=x, column=x)
  • root-将此小部件分配给的父级
  • 文本-设置标签的文本
  • “任何其他选项”-这些选项可以是标签尺寸、特征检查链接以了解更多信息
  • .grid()-将小部件添加到类似网格的布局中的框架中,您可以在其中为行和列定义x

您做过任何研究吗?向输入小部件中插入文本的方法有很好的文档记录。这些人都来自同一个班级吗?最近有这么多计算器/数学相关应用程序lol查看此链接都德:感谢仆从回答这个问题,但谁从中受益,OP真的学到了什么吗?还可以为你的解决方案添加解释。可能不会,但你必须从某个地方开始(我花了很长时间才学会Tkinter)。另外,谢谢你提醒我评论(我确实有很坏的编码习惯…)