Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x Tkinter应该在单独的python文件中,或者可以在相同的代码中?_Python 3.x_Selenium Webdriver_Tkinter - Fatal编程技术网

Python 3.x Tkinter应该在单独的python文件中,或者可以在相同的代码中?

Python 3.x Tkinter应该在单独的python文件中,或者可以在相同的代码中?,python-3.x,selenium-webdriver,tkinter,Python 3.x,Selenium Webdriver,Tkinter,Coordinate_1_X=输入(“输入坐标点01_ux:”) 坐标_1_Y=输入(“输入坐标点01_Y:”) 坐标2\ux=输入(“输入坐标点02\ux:”) 坐标2_Y=输入(“输入坐标点02_Y:”) 坐标_3_X=输入(“输入坐标点03_X:”) 坐标3_Y=输入(“输入坐标点03_Y:”) 坐标_4_X=输入(“输入坐标点04_X:”) Coordinate_4_Y=input(“输入坐标点04_Y:”)下面是一个简单的示例,演示如何在GUI上从用户处获取输入,然后使用函数/方法对其

Coordinate_1_X=输入(“输入坐标点01_ux:”)
坐标_1_Y=输入(“输入坐标点01_Y:”)
坐标2\ux=输入(“输入坐标点02\ux:”)
坐标2_Y=输入(“输入坐标点02_Y:”)
坐标_3_X=输入(“输入坐标点03_X:”)
坐标3_Y=输入(“输入坐标点03_Y:”)
坐标_4_X=输入(“输入坐标点04_X:”)

Coordinate_4_Y=input(“输入坐标点04_Y:”)
下面是一个简单的示例,演示如何在GUI上从用户处获取输入,然后使用函数/方法对其进行处理

import tkinter as tk

class Example(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)

        tk.Label(self, text=" Enter Coordinate point 01 _ X:   ").grid(row=0, column=0)
        self.entry1 = tk.Entry() # this is the widget the user can type in
        self.entry1.grid(row=0, column=1)

        tk.Label(self, text=" Enter Coordinate point 01 _ Y:   ").grid(row=1, column=0)
        self.entry2 = tk.Entry()
        self.entry2.grid(row=1, column=1)
        # This button will run the function that creates a new window with the user input
        tk.Button(self, text="Do something", command=self.do_something).grid(row=2, column=0, pady=5)

    def do_something(self):
        top = tk.Toplevel(self)

        x = self.entry1.get() # the get() method will grab a string of the content of the entry widget
        y = self.entry2.get()

        tk.Label(top, text="You provided coords for point 01 X: {} and Y: {}!".format(x, y)).grid(row=0, column=0)

if __name__ == "__main__":
    Example().mainloop()
结果:

按下按钮后:


Simple创建一个函数,在单击按钮时运行所需代码。这可以通过tkinter按钮和标准功能完成。要允许用户从GUI输入这样的数据,可以使用输入字段,在函数中可以使用
get()
方法从输入字段获取字符串。