English 中文(简体)
框框框
原标题:Binding spinbox to textbox

那么,我们如何能够从1到10个箱中获得价值,然后将其成一个箱(最大:100)? 之后,结果又出现在TKINTER的文字箱中?

我尝试了.get()方法以获得这一数值,然后我将其乘以100。 然后,我使用<代码>.insert()方法,显示结果形成一个文本箱,但该文本却做了一些工作。

问题回答

How can we get the value of a Spinbox (from 1 to 10) then multiply it into a number (ex: 100)

I tried the .get() method to get the value, then I multiplied it by 100. Then I used the .insert() method to display the result in a textbox, but it didn t work that well

  • Add three widgets; Spinbox, Text and Button
  • Create function called value_changed

Edit: re-work in value_changed()

Snippet:

import tkinter as tk
from tkinter import ttk


# root window
root = tk.Tk()
root.geometry( 300x200 )
root.resizable(False, False)
root.title( Spinbox Demo )

def value_changed():
    cal = current_value.get()
    y = 100
    ca= int(cal) * y
    textbox.insert(tk.END, ca)

        
textbox = tk.Text(root, width=25, height=5)
btn = tk.Button(root, text=r Click , command= value_changed)
 
# Spinbox
current_value = tk.StringVar(value=1)
spin_box = ttk.Spinbox(
    root,
    from_=1,
    to=10,
    textvariable=current_value,
    wrap=True)
 
spin_box.pack()
textbox.pack()

btn.pack(pady =10)

root.mainloop()

检查:

“entergraph





相关问题
Validate date textbox

I m using the following code to check if a valid date has been typed into a textbox: public bool ValidateDate(Control ctrl) { if (!string.IsNullOrEmpty(ctrl.Text)) { DateTime value; ...

Opacity of Buttons/TextBoxes - VB.NET

Is it possible to set the opacity of a button or textbox? I know that you can set the opacity for a form, but I m not so sure about a button or textbox.

Auto-scrolling text box uses more memory than expected

I have an application that logs messages to the screen using a TextBox. The update function uses some Win32 functions to ensure that the box automatically scrolls to the end unless the user is viewing ...

WPF TextBox Height Equals Parent Height minus 50 pixels?

I m successfully getting a TextBox to resize with a parent Border height but I need the TextBox to actually be 50 pixels smaller in height than the parent Border. Any ideas how to achieve this? The ...

WPF Masked Textbox with a value that does not contain mask

I need a WPF Textbox that displays a phone number as "(555) 555-5555" but has a value of "5555555555". All of the examples I m seeing have the ability to mask the control on the UI but that affects ...

热门标签