Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.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代码中的GUI_Python_Tkinter - Fatal编程技术网

python代码中的GUI

python代码中的GUI,python,tkinter,Python,Tkinter,我是一个编程初学者,我需要一些帮助,我需要把这个python(3.5.3)代码放到GUI中。我已经读了很多tkinter教程,但没有一本对我有帮助。 我需要将所有输入和打印显示在屏幕上。 代码如下: entrada_salario = float(input("Qual o seu salário mensal? ")) entrada_horas = int(input("Quantas horas você trabalha por dia?")) entrada_dias = int

我是一个编程初学者,我需要一些帮助,我需要把这个python(3.5.3)代码放到GUI中。我已经读了很多tkinter教程,但没有一本对我有帮助。 我需要将所有输入和打印显示在屏幕上。 代码如下:

entrada_salario = float(input("Qual o seu  salário mensal? "))

entrada_horas = int(input("Quantas horas você trabalha por dia?"))

entrada_dias = int(input("Quantos dias por semana você trabalha?"))

horas_trabalhadas = ( entrada_horas * entrada_dias ) * 4

valor_hora = entrada_salario / horas_trabalhadas

custo_cem = 100 / valor_hora

print("Você trabalha" , horas_trabalhadas, "h por mês, recebe R$" , valor_hora,"por hora e seu custo 100 é de %.2f" %custo_cem)

好的,从我所看到的,你只是不了解tkinter或任何GUI的基本知识。也就是说,您确实应该根据教程构建一些程序,这样您就可以掌握GUI

你想做的是非常简单的,即使是最基本的tkinter

下面是如何使用一个简单的GUI来实现这一点

#import Tkinter as tk # this import is for Python 2.x
import tkinter as tk # this import is for Python 3.x

root = tk.Tk() # this is used to define the tkinter wondow

# each label below is for the user to know what to place in each entry box
label1 = tk.Label(root, text = "Qual o seu  salário mensal? ").grid(row = 0, column = 0)
label2 = tk.Label(root, text = "Quantas horas você trabalha por dia?").grid(row = 1, column = 0)
label3 = tk.Label(root, text = "Quantos dias por semana você trabalha?").grid(row = 2, column = 0)

# each entry box configured to be places next to each label. Simple stuff
entry1 = tk.Entry(root)
entry1.grid(row = 0, column = 1)
entry2 = tk.Entry(root)
entry2.grid(row = 1, column = 1)
entry3 = tk.Entry(root)
entry3.grid(row = 2, column = 1)

# this tkinter text box is where we will print out results
text_box = tk.Text(root, height = 2, width = 100)
text_box.grid(row = 4, column = 0, columnspan = 2)

def do_math(): #this function will only work if every entry has a number in it
# I did not spend the time to write in any error checking as this is just an example of what to do.

    # we can get the values of each entry box with .get()
    # make sure we are working with an integer with the int() function.
    horas_trabalhadas = (int(entry2.get()) * int(entry3.get())) * 4
    valor_hora = int(entry1.get()) / horas_trabalhadas
    custo_cem = 100 / valor_hora
    results = "Você trabalha" , horas_trabalhadas, "h por mês, recebe R$" , valor_hora,"por hora e seu custo 100 é de %.2f" %custo_cem

    # this is the command to print results to the text box.
    text_box.delete(1.0, "end-1c")
    text_box.insert("end-1c", results)
    text_box.see("end-1c")

# this button is configured to call the do_math(): function when it is pressed
submit_button = tk.Button(root, text = "Submit", command = do_math).grid(row = 3)

root.mainloop() # required at then end of your tkinter program

你需要解释一下你想做什么。“我需要把这个python代码放在GUI中”这句话含糊不清,令人痛苦。实现什么目标?GUI甚至应该做什么?你已经试过什么了?教程是我开始学习的地方,如果你学习并观看本教程或其他一些教程,你可以将你的代码放入tkinter。因此,从我所看到的是,你正在进行一些数学运算,并将一些结果打印到控制台。根据您的陈述,您需要GUI中的
代码,我只能假设这意味着您需要一些输入框,用户可以在其中输入数字,然后有某种提交按钮,并在屏幕上显示结果。您的问题毫无疑问。你需要什么帮助?首先,根据你从教程中学到的知识创建一个tkinter程序,然后告诉我们你遇到了什么困难。主要问题是:我不知道如何在吉他上输入和打印这是我需要的,非常感谢。