ProblemWe are required to write a JavaScript function that takes in two arrays of numbers, arr1 and arr2, as the first and the second arguments.Our function should merge the elements of both these arrays into a new array and if upon merging or before merging there exists any duplicates, we should delete the excess duplicates so that only one copy of each element is present in the merged array.The order here is not so important but the frequency of elements (which should be 1 for each element) is important.For example, if the input to the function is −onst arr1 = ... Read More
ProblemWe are required to write a JavaScript function that takes in a number, num, as the first and the only argument.Our function should return true if the sum of the digits of the number num is a palindrome number, false otherwise.For example, if the input to the function is −const num = 781296;Then the output should be −const output = true;Output ExplanationBecause the digit sum of 781296 is 33 which is a palindrome number.ExampleFollowing is the code − Live Democonst num = 781296; const findSum = (num, sum = 0) => { if(num){ return findSum(Math.floor(num / 10), sum + (num ... Read More
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a number, num, (num { const res = []; let sum = 0, right = 0, left = 0; for(; right < num; right++){ sum += arr[right]; }; res.push(sum); while(right < arr.length){ sum -= arr[left]; sum += arr[right]; right++; left++; res.push(sum); }; return res; }; console.log(accumulateArray(arr, num));OutputFollowing is the console output−[3, 5, 7, 9, 11]
ProblemWe are required to write a JavaScript function that takes in two arrays of literals, arr1 and arr2, as the first and the second argument.Our function should find out the common element in arr1 and arr2 with the least list index sum. If there is a choice tie between answers, we should output all of them with no order requirement.For example, if the input to the function is− Live Democonst arr1 = ['a', 'b', 'c', 'd']; const arr2 = ['d', 'a', 'c'];Then the output should be −const output = ['a'];Output ExplanationSince 'd' and 'a' are common in both the arrays the ... Read More
Images are very useful objects in any application. We can process Images in a Tkinter application using the Pillow or PIL package in Python. There are several built-in functions such as loading an image, extracting an image, configuring the image pane, etc.ExampleIn this example, we will add by asking the user to select an image from a dialog box and then, display it using the Label widget.#Import the Tkinter library from tkinter import * from tkinter import ttk from tkinter import filedialog from PIL import Image, ImageTk #Create an instance of Tkinter frame win= Tk() #Define the geometry win.geometry("750x350") win.title("Image ... Read More
Let us assume that we want to check if a particular widget has a focused set or not. The only way to check the widget focus is to use the utility method focus_get(). It returns the object containing the widget’s information which is currently focused on, during the program’s execution. We will use the focus_get() method to find the active widget during our program’s execution.ExampleIn this example, we have created an Entry widget that will get its focus when we press the key. The focus_get() method will return the current widget’s information which is active.#Import the Tkinter library from ... Read More
Callback functions in Tkinter are generally used to handle a specific event happening in a widget. We can add an event callback function to the Entry widget whenever it gets modified. We will create an event callback function by specifying the variable that stores the user input. By using the trace("mode", lambda variable, variable: callback()) method with the variable, we can trace the input on the Label widget in the window.Example#Import the Tkinter library from tkinter import * #Create an instance of Tkinter frame win= Tk() #Define the geometry win.geometry("750x250") def callback(var): content= var.get() Label(win, text=content).pack() #Create an ... Read More
There are times when a user wants to insert the information like Name, contact number, Email, address, etc. Tkinter has a simple way to handle these types of inputs through its Entry widgets. Tkinter Entry widgets can be styled using the ttk package.To change other properties of the Entry widgets such as font properties, text-size, and font-style, we can use the font(‘font-family font-size font-style’) attribute. We can specify the font property in the entry constructor.Example#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter ... Read More
In this example, we will see how to resize a tkinter window using the geometry manager. Tkinter geometry manager is generally used to configure the width and height of a tkinter window.The geometry(width, height)method takes width and height as instances and resizes the window accordingly. We can also define the position of the tkinter window by adding geometry(width x height, X, Y) where x and y are horizontal and vertical positions of the window.Example#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter frame ... Read More
Let us suppose that for a particular application, we want to retrieve the button value by its name. In such cases, we can use the .cget() function. Every tkinter widget supports the .cget() function, as it can be used to retrieve the widget configuration such as value or name.ExampleIn this particular example, we will create a button and then store the button text in a variable "mytext". Using the variable, we will display the text in a Label widget.#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP