Found 33676 Articles for Programming

FTP protocol client in Python

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

1K+ Views

The all important The FTP class in ftplib module implements the client side of the FTP protocol.To establish connection with a FTP server, obtain FTP object.con=FTP(hostname)The FTP class supports following methods −connect()Connect to the given host and port. The default port number is 21, as specified by the FTP protocol specification.Getwelcome()Return the welcome message sent by the server in reply to the initial connection.login(user='anonymous', passwd='', acct='')Log in as the given user. The passwd and acct parameters are optional and default to the empty string. If no user is specified, it defaults to 'anonymous'. If user is 'anonymous', the default passwd ... Read More

zipapp - Manage executable Python zip archives

Arushi
Updated on 30-Jul-2019 22:30:26

680 Views

The zipapp module has been introduced in Python's standard library since ver 3.5. This module is used to manage the creation of zip files containing Python code, which can be executed directly by the Python interpreter. The module provides both a Command-Line Interface and a programming interface.To use zipapp module programmatically, we should have a module in which main function is present. The executable archive is built by following command −python -m zipapp myapp -m "example:main"Here, the current path should have a folder called myapp. In this folder, there should be example.py which must have main() function.Create myapp folder and ... Read More

Access to the underlying platform’s identifying data in Python

Arushi
Updated on 30-Jul-2019 22:30:26

256 Views

Functions in the platform module help us probe the underlying platform’s hardware, operating system, and interpreter version information.architecture()This function queries the given executable (defaults to the Python interpreter executable) for various architecture information.>>> import platform >>> platform.architecture() ('64bit', '')machine()This function returns the machine type, e.g. 'i386'. An empty string is returned if the value cannot be determined.>>> platform.machine() 'x86_64'node()This function returns the computer’s network name.>>> platform.node() 'malhar-ubuntu'platform(aliased=0, terse=0)This function returns a single string identifying the underlying platform.>>> platform.platform() 'Linux-4.13.0-46-generic-x86_64-with-debian-stretch-sid'processor()This function returns the (real) processor name.>>> platform.processor() 'x86_64'python_build()This function returns a tuple (buildno, builddate)>>> platform.python_build() ('default', 'Oct 13 2017 12:02:49')python_compiler()This function ... Read More

C-style parser for command line options in Python

Rishi Raj
Updated on 30-Jul-2019 22:30:26

349 Views

Python’s sys module provides access to any command-line arguments via the sys.argv. sys.argv is the list of command-line arguments and sys.argv[0] is the program ie. the script name.Save following code as args.pyimport sys print ('argument list', sys.argv)Execute above script from command line as follows:C:\python37>python args.py 11 22 argument list ['args.py', '11', '22']The getopt module has funcions toparse the command line arguments in sys.argv. It supports the same conventions as the Unix getopt() function (including the special meanings of arguments of the form ‘-‘ and ‘--‘).API is designed to be familiar to users of the C getopt() function.getopt(args, shortopts, longopts=[])Parses command ... Read More

Draw a border around an undecorated JFrame in Java

Samual Sam
Updated on 30-Jul-2019 22:30:26

784 Views

At first, set an undecorated frame −setUndecorated(true);Now draw a border −getRootPane().setBorder (.createMatteBorder(3, 3, 3, 3, Color.ORANGE));The following is an example to draw a border around an undecorated JFrame −Exampleimport java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo extends JFrame {    JLabel label = new JLabel("Welcome!", JLabel.CENTER);    public SwingDemo() {       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       setSize(new Dimension(500, 300));       add(label, BorderLayout.CENTER);       setUndecorated(true);       getRootPane().setBorder(          BorderFactory.createMatteBorder(3, 3, 3, 3, Color.ORANGE));       setVisible(true);    }    public static void main(String[] args) {       new SwingDemo();    } }Output

How to create modeless and model JDialog in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

580 Views

MODELESS TypeThe following is an example to set JDialog with Modality type MODELESS −Exampleimport java.awt.Cursor; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setSize(new Dimension(600, 400));       JDialog dialog = new JDialog(frame, "New", ModalityType.MODELESS);       dialog.setSize(300, 300);       frame.add(new JButton(new AbstractAction("Click to generate") {          @Override          public void actionPerformed(ActionEvent e) {             frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));   ... Read More

How to set default button for JFrame in Java?

Samual Sam
Updated on 30-Jul-2019 22:30:26

1K+ Views

To set default button for JFrame, use the setDefaultButton() method −JFrame frame = new JFrame(); frame.getRootPane().setDefaultButton(button);The following is an example to set default button for JFrame −Exampleimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo {    public static void main(String args[]) {       JButton button = new JButton("Demo Button!");       JFrame frame = new JFrame();       frame.setSize(500, 300);       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.getRootPane().setDefaultButton(button);       button.setMnemonic(KeyEvent.VK_A);       button.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent ae) {         ... Read More

How to set minimum size limit for a JFrame in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

2K+ Views

Use the setMinimumSize() method to set the minimum size limit for a JFrame −JFrame frame = new JFrame(); frame.setMinimumSize(new Dimension(500, 300));The following is an example to set minimum size limit for a JFrame −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JButton button = new JButton("Close!");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setContentPane(button);       button.addActionListener(e -> {          frame.dispose();       });       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setMinimumSize(new Dimension(500, ... Read More

Get JFrame window size information in Java

Samual Sam
Updated on 30-Jul-2019 22:30:26

3K+ Views

To get JFrame window size information, you can use the following −environment.getMaximumWindowBounds();For Screen Size −config.getBounds()For Frame Size −frame.getSize());The following is an example to get JFrame window size information −Exampleimport java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();       Rectangle bounds = environment.getMaximumWindowBounds();       System.out.println("Screen Bounds = " + bounds);       GraphicsDevice device = environment.getDefaultScreenDevice();       GraphicsConfiguration config = device.getDefaultConfiguration();       System.out.println("Screen Size = " + config.getBounds());       JFrame frame ... Read More

How can we clear all selections in Java Swing JList?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

677 Views

To clear all selections, use the List clearSelection() method in Java −JList list = new JList(sports); list.clearSelection();Above, the elements in Sports array is a String array −String sports[]= { "Cricket", "Football", "Hockey", "Rugby"};The following is an example to clear all selection in JList −Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame {    static JFrame frame;    static JList list;    public static void main(String[] args) {       frame = new JFrame("JList Demo");       SwingDemo s = new SwingDemo();       JPanel panel = new JPanel();       String sports[]= ... Read More

Advertisements