python 游戏脚本搜索框怎么输入文本_用按钮从Tkinter条目搜索框中获取文本

我对python很陌生,我刚开始学Tkinter。我想做一些自我锻炼的档案。到目前为止还不错,但是我遇到了一个问题(我将发布整个代码,之后我将继续解决问题,这样您就可以看到我想要做什么,以及我不知道如何做的地方)。在#!/usr/bin/python

from tkinter import *

from PIL import Image, ImageTk

import subprocess

class Window(Frame):

def __init__(self, master = None):

Frame.__init__(self, master)

self.master = master

self.init_window()

def init_window(self):

self.master.title("ez-Installer")

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

updateButton = Button(self, text="Update", command=self.system_update)

updateButton.place(x=50, y=50)

syncButton = Button(self, text="Sync packages", command=self.system_sync)

syncButton.place(x=150, y=50)

cmd1 = StringVar()

mEntry = Entry(self,textvariable=cmd1).pack()

installButton = Button(self, text="Install", command=self.system_install)

installButton.place(x=50, y=150)

def system_install(self):

package = cmd1.get()

install = "sudo pacman -S {} --noconfirm".format(package)

subprocess.call([install], shell=True)

def system_exit(self):

exit()

def system_update(self):

subprocess.call(["sudo pacman -Su --noconfirm"], shell=True)

def system_sync(self):

subprocess.call(["sudo pacman -Syy --noconfirm"], shell=True)

root = Tk()

root.geometry("400x300")

app = Window(root)

root.mainloop()

错误出现在按下“安装”按钮时未定义cmd1。在

^{pr2}$

如您所见,我希望它从我在此处添加的搜索框条目中获取文本:cmd1 = StringVar()

mEntry = Entry(self,textvariable=cmd1).pack()

installButton = Button(self, text="Install", command=self.system_install)

installButton.place(x=50, y=150)

我知道我的条目在def init_window(self):下,但是我如何从那里获取{}的值呢?有可能吗?如果不是,或者是太麻烦了,那么类似的替代方案是什么?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值