Answer the question
In order to leave comments, you need to log in
How to change font size according to its size and PyQt5 label size?
How to resize text according to its size and PyQt5 label's size?
If the font size is too large, then it often goes beyond the label. In my project, the text changes to unknown to me, so I need to somehow automate the change in font size in accordance with its size and the size of the label.
Answer the question
In order to leave comments, you need to log in
Each time the function is called, a new variable is declared and a new interval is created. The interval stops, but not the one that was created during the previous call, but a new one.
var snake = {
interval : {
right : function (start){
if( start == "stop"){
clearInterval(this.inter);
} else {
this.inter = setInterval(function(){}, 500)
}
}
}
};
snake.interval.right();
snake.interval.right("stop");
Because when you handle the 'stop' parameter, you still start an infinite loop and naturally the script does not reach the check for start=='stop'.
You need to create a generic element and 2 functions for start and stop. For more details and even with examples on the stack, follow this link .
var snake = {
interval : {
interval_id: null,
right : function (stop){
if (stop) {
return clearInterval(this.interval_id);
}
if (this.interval_id) {
clearInterval(this.interval_id);
}
this.interval_id = setInterval(snake.functions.moveRight, 500);
}
}
}
snake.interval.right();
snake.interval.right(true);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question