variables

Tkinter Label not showing Int variable

守給你的承諾、 提交于 2021-02-08 12:02:36
问题 I'm trying to make a simple RPG where as you collect gold it will be showed in a label, but it doesn't!! Here is the code: def start(): Inv=Tk() gold = IntVar(value=78) EtkI2=Label(Inv, textvariable=gold).pack() I'm new to python and especially tkinter so I need help!!! 回答1: The only thing wrong with your code is that you aren't calling the mainloop method of the root window. Once you do that, your code works fine. Here's a slightly modified version that updates the value after 5 seconds:

Using variable value as variable name in bash

試著忘記壹切 提交于 2021-02-08 11:59:36
问题 I've seen this question asked before but I can't seem to get the grasp of it. I have this variable that I get from user input read column_number and then I join it with the "col" prefix to form the name of my variable selected_column="col"$column_number But when I try to evaluate it to get the result, I keep getting the (standard_in) 1: syntax error sum=$(round $sum+"echo ${!selected_column}", 2) full code: 回答1: column_number=5 selected_column=col$column_number col5=42 sum=17 echo $(($sum+${

Groovy - Define variable where the variable name is passed by another variable

淺唱寂寞╮ 提交于 2021-02-08 11:23:23
问题 I want define a variable in groovy with where the variable name is passed by another variable. Something like. def runExtFunc(varName){ def varName // => def abc varName = load 'someFile.groovy' // abc = load 'someFile.groovy' varName."$varName"() // -> abc.abc() (run function defined in File) } [...] runExtFunc('abc') // -> abc.abc() (Function abc defined in File) [...] runExtFunc('xyz') // -> xyz.xyz() (Function xyz defined in File) [...] Sadly def varName defines the variable varName and

Ruby - local variable gets modified when changing instance variable

半城伤御伤魂 提交于 2021-02-08 10:44:23
问题 temp gets @board.dup , and @board array is modified. However, temp gets modified as well! I have tried reading all the related documentations but still couldn't figure out an explanation. class Test def initialize @board = [[1,2],[3,4], [5,6]] end def modify temp = @board.dup #Also tried .clone print 'temp: ';p temp print '@board: ';p @board @board.each do |x| x << "x" end print "\ntemp: ";p temp print '@board: ';p @board end end x = Test.new x.modify Output: temp: [[1, 2], [3, 4], [5, 6]]

Ruby - local variable gets modified when changing instance variable

故事扮演 提交于 2021-02-08 10:43:16
问题 temp gets @board.dup , and @board array is modified. However, temp gets modified as well! I have tried reading all the related documentations but still couldn't figure out an explanation. class Test def initialize @board = [[1,2],[3,4], [5,6]] end def modify temp = @board.dup #Also tried .clone print 'temp: ';p temp print '@board: ';p @board @board.each do |x| x << "x" end print "\ntemp: ";p temp print '@board: ';p @board end end x = Test.new x.modify Output: temp: [[1, 2], [3, 4], [5, 6]]

Powershell reading multiple variables from text file

孤街浪徒 提交于 2021-02-08 10:20:27
问题 I'm quite new to PS, so please don't kill me if the resolution is so easy :) I've tried to find a solution here and in google, but no luck. This is part of code which don't work as I want $Contents = Get-Content "Path\test.txt" foreach($Line in $Contents) { $Line = $Line.split(":")[1] $s = $line -split ':' $RegPath = $s[0] $Value_Name = $s[1] $Type = $s[2] $Value = $s[3] Write-host $RegPath $Value_Name $Type $Value } The output from Write-Host is ok, but the main problem is when I want to use

Powershell reading multiple variables from text file

拈花ヽ惹草 提交于 2021-02-08 10:20:16
问题 I'm quite new to PS, so please don't kill me if the resolution is so easy :) I've tried to find a solution here and in google, but no luck. This is part of code which don't work as I want $Contents = Get-Content "Path\test.txt" foreach($Line in $Contents) { $Line = $Line.split(":")[1] $s = $line -split ':' $RegPath = $s[0] $Value_Name = $s[1] $Type = $s[2] $Value = $s[3] Write-host $RegPath $Value_Name $Type $Value } The output from Write-Host is ok, but the main problem is when I want to use

Python create variable for each item

▼魔方 西西 提交于 2021-02-08 09:54:40
问题 I have a list of items. like banana , apple , orange etc. Each of these has it´s properties, like banana : 'name': 'banana','color': 'yellow' etc. What I'm trying to do is create variable's for each item. So i can call it like fruit.banana['color'] and get the value yellow back. Code example: fruits = cur.fetchall() for fruittarget in fruits: fruit = fruittarget['name'] cur.execute("SELECT * FROM fruits where name = %s ;",(fruit)) rows = cur.fetchone() name = rows["name"] fruitfunc = {name:

Variable not available to sub-function [duplicate]

一笑奈何 提交于 2021-02-08 09:54:38
问题 This question already has answers here : Why doesn't a sub-function inherit scope in Python? (2 answers) Closed 3 years ago . This script defines a variable inside main() , but the variable isn't available to func() , which runs inside main() . Why is that? #!/usr/bin/env python3 # vars_in_func.py # Test script for variables within a function. def func(): print(greeting) def main(): greeting = "Hello world" func() main() Error: Traceback (most recent call last): File "./vars_in_func.py", line

Passing Powershell variable to Windows Batch file

五迷三道 提交于 2021-02-08 09:16:30
问题 Due to restrictions around my project and how this is being deployed, I need to run a powershell command in a batch file and echo a variable from the powershell script. This scripts retrieves a model number from a TV over RS-232 and returns the model in HEX. I wrote the script and meticulously condensed it to one line that runs. I can even 'powershell -command "[myCondensedScript]"' in the command line and it works great for /F %%a in ('powershell.exe -command "$port = New-Object System.IO