create multiple tabs in a loop with scrollbard in tkinter - loops

I want to create multiple tabs in a loop with scrollbars in tkinter. Somehow the scrollbar only works in the last tab with the following code:
for i in range(ParameterTabNumber):
z=ParameterTabs[i]
FrameParametersMain=Frame(MainNotebook, background="#FFFFFF", width=200, height=150)
FrameParametersMain.pack()
MainNotebook.add(FrameParametersMain, text=str(z))
my_FrameParametersMain.append(FrameParametersMain)
canvasParameters = Canvas(FrameParametersMain, highlightthickness=0,bg='#FFFFFFF')
canvasParameters.pack(side=LEFT, fill=BOTH, expand=1)
my_CanvasParameters.append(canvasParameters)
scrollbarParameters = Scrollbar(FrameParametersMain, orient=VERTICAL, command=canvasParameters.yview)
scrollbarParameters.pack(side=RIGHT, fill=Y)
my_scrollbarParameters.append(scrollbarParameters)
FrameParameters = Frame(canvasParameters)
my_TopTabs.append(FrameParameters)
canvasParametersWidgits = Canvas(FrameParameters, highlightthickness=0,bg='#FFFFFF',width=1700, height=1000)
canvasParametersWidgits.pack()
canvasParameters.create_window((0,0), window=FrameParameters, anchor="nw")
canvasParameters.configure(yscrollcommand=scrollbarParameters.set)
canvasParameters.bind('<Configure>',lambda e: canvasParameters.configure(scrollregion = canvasParameters.bbox("all")))
Can someone help me to get this working please?
Vielen Dank.

It is because you have used same variable canvasParameters inside the lambda. You should use e.widget instead:
canvasParameters.bind('<Configure>',lambda e: e.widget.configure(scrollregion = e.widget.bbox("all")))

Related

How to keep data after closing the program.(without using textfile,data outside)

Example :
1.When i using program start int x = 5;
2.Do something until x = 10
3.Closing program
4.When a relaunch program x will be equal to 10 (not 5)
Here the Application Setting will come into play.
Proiperties -> Settings
This will strore our data as XMl formatted.
Action can be applied through both programmatically and manually.
Programmatically:
Create:
SettingsProperty property = new SettingsProperty(nameofthesetting);
property.DefaultValue = "Default";
property.IsReadOnly = false;
property.PropertyType = typeof(bool);
property.Provider = Properties.Settings.Default.Providers["LocalFileSettingsProvider"];
property.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute());
Properties.Settings.Default.Properties.Add(property);
Properties.Settings.Default.Reload();
property.DefaultValue = HereYourValue;
Update :
Settings.Default.YourSettingsName=NewValue
Settings.Default.Save();
Settings.Default.Reload();
reference,
How do I get around application scope settings being read-only?
How to update appSettings in a WPF app?

Please assist to remove last comma from while loop

You're probably assuming this is a duplicate content. It is NOT. I tried all the solutions. Here's the problem.
If you use any solution (substr, rtrim, etc.) inside the while loop, it removes them from each looped item. If you use any solution outside of the while loop, then only the last item of your while loop will show.
Solution inside while loop:
(a,b,c,d,e,) becomes (abcde)
Solution outside while loop:
(a,b,c,d,e,) becomes (e).
Much clarification on this is much appreciated. Thank You for the help! Yes, I've been working on this six hours now. Please help me solve this issue.
Here's my code (without the solution in it):
<script type="text/javascript">
states=new array (<?php $query18 = "SELECT * FROM states ORDER BY state ASC";
$result18 = $db->query($query18);
while ($row18 = $result18->fetch(PDO::FETCH_ASSOC)) {
$states4 = $row18['state'];
$states5 = "\"$states4\",";
echo $states5;
} ?> ); </script>
I am trying to get my list of states (from database) into an array in javascript.
It seems you have not closed closing bracket of array.
Which should be,
states=new array (<?php $query18 = "SELECT * FROM states ORDER BY state ASC"; $result18 = $db->query($query18); ?>);
I don't know much of JavaScript, but you could change your logic as below:
first=1;
while(there-is-data) {
$states4 = ...
if (first) {
first = 0;
$states5 = $states4;
} else {
$states5 = ","\$states4;
}
} // while
You concatenate a comma and the new data for all iterations except the first. For the first, you exclude the comma.

Creating button on corona using one line) but adding the function fails

Been researching but no luck. Creating a button on Corona SDK requires several lines. (Corona SDK reference here). If you create 5 buttons the code grows a lot, so I created a function that I can call with just one liner and creates the buttons I need. It works fine but can't sort the events.
cbutton = function (nbutton, tbutton, blabel, bfs, bx, by)
bfcolor={default = { 51, 51, 51, 215 }}
if tbutton == "default-1" or tbutton == "default-2" or tbutton == "default-3" then bfcolor = nil end
local button1 = widget.newButton
{
defaultFile = "assets/" .. tbutton .. ".png",
overFile = "assets/o" .. tbutton .. ".png",
label = blabel,
labelColor = bfcolor,
fontSize = bfs,
emboss = true,
onPress=botonhrPress // <-- HERE, THIS PART
}
button1.x = bx; button1.y = by
end
cbutton("b1","primary-1","Create account", 20, 160, 160)
So, here is the thing.
The code above works, it creates the button.
Using the last line, calls the function and creates the button
It used the parameters
The part that says "HERE" works, ties the event to the button
BUT, it's directly written, can't pass parameters there
Tried concatenation, a full string variable with the name of the local function, also %, &, () and {} to enclose the data, no luck. If we can work around this part then we could create buttons with just one line of code + the function posted here. Any ideas will be appreciated, thanks in advance.

image array and .src - image not changing

I have created an array which is being used to store a series of .gif images and I'm just trying to test everything out by using document.getElementById to change the .src value but when I change it and load the page the image stays the same as it was before.
function setImage()
{
var images = new Array();
images[0] = anemone.gif;
images[1] = ball.gif;
images[2] = crab.gif;
images[3] = fish2.gif;
images[4] = gull.gif;
images[5] = jellyfish.gif;
images[6] = moon.gif;
images[7] = sail.gif;
images[8] = shell.gif;
images[9] = snail.gif;
images[10] = sun.gif;
images[11] = sunnies.gif;
images[12] = whale.gif;
var slots = new Array();
slots[0] = document.getElementById("slot" + 0);
slots[1] = document.getElementById("slot" + 1);
slots[2] = document.getElementById("slot" + 2);
slots[0].src = "snail.gif";
document.getElementById('slot0').src = images[0];
alert(images.length);
}
I can't understand why the image wont change, but I know it has to be something very simple. I've been wasting hours trying to get this one thing to change but nothing works. can anyone please point out the error of my ways?
There are a couple of issues with your code:
Your filenames need to be Strings, so they'll have to be quoted (also you can simplify the Array creation):
var images = ['anemone.gif', 'ball.gif', 'crab.gif', 'fish2.gif', 'gull.gif', 'jellyfish.gif', 'moon.gif', 'sail.gif', 'shell.gif', 'snail.gif', 'sun.gif', 'sunnies.gif', 'whale.gif'];
Also make sure you are getting your slot-elements right, quote all the attributes like:
<img id="slot0" class="slot" src="crab.gif" width="120" height="80">
When you create the slots-Array you can do it like this (no need to concat the ID string):
var slots = [document.getElementById('slot0'), document.getElementById('slot1'), document.getElementById('slot2')];
Finally make sure you call your function when the document has loaded / the DOM is ready. If you don't want to use a framework like jQuery your easiest bet is probably still using window.onload:
window.onload = setImage; //note that the parens are missing as you want to refer to the function instead of executing it
Further reading on Arrays, window.onload and DOMReady:
https://developer.mozilla.org/de/docs/DOM/window.onload
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array
javascript domready?

Trying To Prevent Repost Data on refresh

working with pre existing code just a simple patch i added ontop
//first get the variables
bridge = namef & valuef
//a paranoid double check
if session("gap") = session("oldgap") then session("gap") = "null"
//the actual comparison
if bridge = session("gap") then
drawbridge = ""
else
drawbridge = inputscrubber("action")
end if
session("oldgap") = session ("gap")
session("gap") = namef & valuef
You should use the PRG (Post/Redirect/Get) pattern to avoid such issues.
The idea is that once the form is posted, you process it and redirect to a different page. The user at this point can refresh without any issue.

Resources