Can someone help me rewrite this java program in python. This program takes a message from the shell and flashes the message one word at a time.

Now I am supposed to rewrite it in python (tkinter), I have the gui done and my quit button works, but I cannot seem to figure the thread part out.

Please help this is due in 2 days and I only have 1/4 of it rewrote in python.

Thanks in advance.

Here is the program in java.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FlashingText extends JFrame implements ActionListener{

public static void main(String []args){
for (int i = 0; i < args.length; i++)
System.out.println("Args: " + args );

//Create the frame and set a title
JFrame frame = new JFrame ("Flashing Text");

JPanel textPanel = new JPanel();
textPanel.setBackground(Color.black);
Lights lights = new Lights (args);
textPanel.add(lights);

//Set the frame layout
frame.setLayout(new FlowLayout());

//Create a quit button and add an action listener to the button

JPanel quitPanel = new JPanel();
JButton quitbutton = new JButton("QUIT");
quitPanel.add(quitbutton);
quitbutton.addActionListener( new FlashingText () );

// Add the components to the frame
Container content = frame.getContentPane();
content.add(quitPanel);
content.add(textPanel);


//Set the size of the frame and set to visible
frame.setSize(100, 50);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent ae){
System.exit(0);
}
}


Second class:

import java.awt.*;
import javax.swing.*;

public class Lights extends JPanel implements Runnable {

Font textFont = new Font("Serif", Font.BOLD, 20);
Thread runner;
JLabel [] input;

public Lights(String [] message) {

input = new JLabel [message.length];
for (int i = 0; i < message.length; i++){
input = new JLabel(message);
this.add(input);
}

runner = new Thread(this);
runner.start();
}

void pause(int duration) {
try {
Thread.sleep(duration);
} catch (InterruptedException e) { }
}

public void run() {
while ( true ) {
for (int i = 0; i < input.length; i++){
input.setForeground(new Color (180, 150, 195));
pause(70);
pause(70);
}

for (int i = 0; i < input.length; i++){
input.setForeground (Color.black);
pause(70);
pause(70);
}
}
}
}

Member Avatar for iamthwee

ask that in the python forums

Sorry but you may not ask members to do your homework for you. It is against the forums guidelines. Please do this yourself and ask for help only when necessary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.