python tkinter button判断执行下一步_python tkinter button命令在执行时执行命令,而不是按按钮时执行命令...

这篇博客讲述了作者在学习Python时遇到的一个问题,即使用Tkinter创建GUI时,一个用于扫描的按钮在启动时就执行了功能,而没有按预期在点击后才运行。作者在GUI中设置了输入字段来获取参数,并希望通过点击“开始扫描”按钮调用另一个模块的端口扫描功能。问题在于,这个功能在程序启动时就被执行了,而不是在按钮被点击时。博客内容涉及到Tkinter界面设计和模块交互。
摘要由CSDN通过智能技术生成

我目前正在学习python,并尝试使用一个tkinter按钮将变量从几个输入字段传递到另一个文件中的函数。

该按钮调用另一个模块内的扫描功能。在

由于某些原因,我一开始就执行这个功能,而不是点击按钮。我不明白为什么。

“开始扫描”按钮下的“查找”按钮

我希望得到你的支持from tkinter import *

from PIL import Image, ImageTk

from Sockets_Portscanner_threaded import *

# Here, we are creating our class, Window, and inheriting from the Frame

# class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)

class Window(Frame):

# Define settings upon initialization. Here you can specify

def __init__(self, master=None):

# parameters that you want to send through the Frame class.

Frame.__init__(self, master)

#reference to the master widget, which is the tk window

self.master = master

#with that, we want to then run init_window, which doesn't yet exist

self.init_window()

#Creation of init_window

def init_window(self):

# changing the title of our master widget

self.master.title("GUI")

# allowing the widget to take the full space of the root window

self.pack(fill=BOTH, expand=1)

####################

# FORM #

####################

#Grid labels

Label(self, text="Please enter the Parameters For portscanning!").grid(row=0, column=1)

Label(self, text="Server/domain").grid(row=2)

Label(self, text="Ports:").grid(row=4, column=0)

Label(self, text="From").grid(row=5)

Label(self, text="To").grid(row=6)

# creating a entry forms

E1 = Entry(self)

E2 = Entry(self)

E3 = Entry(self)

# placing entry forms in grid

E1.grid(row=2, column=1)

E2.grid(row=5, column=1)

E3.grid(row=6, column=1)

# Setting defaul variables for entry

E1.insert(10,'localhost')

E2.insert(10,'1')

E3.insert(10,'500')

####################

# \FORM #

####################

# Start Scanning button

Button(self, text='Show', command=scan(E1.get(),E2.get(),E3.get())).grid(row=7, column=1, sticky=W, pady=4)

def client_exit(self):

exit()

# root window created. Here, that would be the only window, but

# you can later have windows within windows.

root = Tk()

root.geometry("400x300")

#creation of an instance

app = Window(root)

#mainloop

root.mainloop()

此按钮中的扫描功能位于套接字扫描程序线程文件中

^{pr2}$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值