如何获取条目的值并将其输入到 Ssol.txt 中? [英] How do I get the value of an entry and enter it in Ssol.txt?

查看:31
本文介绍了如何获取条目的值并将其输入到 Ssol.txt 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from tkinter import *
from tkinter import ttk

win = Tk()
win.title("hello")
win.geometry('510x50+200+100')
Block = IntVar()

def x():
    k = open("Ssol.txt", 'w')

Entry(win, width=5, textvariable=Block).grid(column=1, row=0,sticky=(N,W,E))
ttk.Button(win, text="실행", command=x).grid(column=0, row=1,sticky=(W,E))

mainloop()

我想获取 entry 的值并输入到 Ssol.txt 中.

I want to get the value of entry and input it in Ssol.txt.

def x():
    k = open("write_Value.txt", 'w')

我能理解这一点,但我在 Google 中搜索输入时不理解那么我想知道如何获取 Entry 值并将其输入到 Ssol.txt 中.:)

I can understand this but I do not understand when I search for input in Google so then I want to know how to get the Entry value and enter it in Ssol.txt. :)

推荐答案

您需要使用 .get() 来访问您的 IntVar 的值:

You need to use .get() to access the value of your IntVar:

from tkinter import *

win = Tk()
Block = IntVar()

def Block_to_file():
    contents = str(Block.get())
    with open("Ssol.txt", 'w') as f:
        f.write(contents)

Entry(win, width=15, textvariable=Block).grid(column=0, row=0, sticky=(N, W, E))
Button(win, text='Write to file', command=Block_to_file).grid(column=0, row=1, sticky=(W, E))

mainloop()

这篇关于如何获取条目的值并将其输入到 Ssol.txt 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆