I thought it would be fun to code all the different ways to show Hello World on the display.

Let's start simple ...
print("Hello World")

Can anybody print out "Hello World" vertically?

Now for something completely different, slicing ...
print("dlroW olleH"[::-1])

Mildly more complex using the ASCII values ...

hello_list = [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]
print("".join(chr(x) for x in hello_list))

Who ever heard of Caesar Cipher ...

encrypted = "Ifmmp!Xpsme"
print("".join(chr(ord(x)-1) for x in encrypted))

Anybody ready to use a GUI with a fancy font?

Oh Gee, the response is overwhelming, here is one GUI attempt ...

# for Python2 change tkinter to Tkinter
import tkinter as tk

root = tk.Tk()
mytext = " Hello World "
myfont = ('times', 48, 'bold')
label = tk.Label(root, text=mytext, font=myfont, fg='red', bg='yellow')
label.pack()
root.mainloop()

I don't think Tkinter looks homely all the time.
IMHO, Tkinter looks best in OSX.

Member Avatar for iamthwee

Does tkinter support a native look and feel in 'said' OS?

print("Hello World")

Can anybody print out "Hello World" vertically?

print('\n'.join("Hello World"))

Vertical slanted left to right ...

print('\n'.join(" "*ix + c for ix, c in enumerate("Hello World")))

Now if I only could slant it right to left.

Pyside/PyQT allows you to use HTML code ...

from PySide.QtGui import *

app = QApplication([])

s_html = '''\
<font face="Courier" color=red size=7><p><i> {} </i></p></font>
'''.format("Hello World")
label = QLabel(s_html)
label.show()

app.exec_()

left to right but it's increasing upwards :P

print '\n'.join(" "*ix + c for ix, c in reversed(list(enumerate("Hello World"))))
pyTony's version backwards vertically

print('\n'.join("Hello World"))[::-1]

Some less common string methods anyone?

s = "hello world"
print(" ".join(word.capitalize() for word in s.split()))
# simpler ...
print(s.title())
# more ...
print(s.title().center(20))
print(s.title().swapcase())

Here little bigger version

hello = dict(zip('helo wrd'.upper(),'''
 *  *
 *  *
 ****
 *  *
 *  *

 ****
 *
 ****
 *
 ****

 *
 *
 *
 *
 ****

  ***
 *   *
 *   *
 *   *
  ***






*  *  *
*  *  *
*  *  *
 *  *

 ****
 *   *
 *  *
 ***
 *  *
 *   *

 ***
 *  *
 *  *
 *  *
 ***
'''.split('\n\n')))


print('\n\n'.join(hello[c] for c in 'Hello world'.upper()))

@pytony it says HELLO OWLR, there must be something wrong.

This one looks better with python 3

import cgitb, os, sys, tempfile, webbrowser

dst = os.path.join(tempfile.gettempdir(), 'helloworld.html')
try:
    raise type('Hello World', (Exception,),{})
except:
    with open(dst, 'w') as ofh:
        ofh.write(cgitb.html(sys.exc_info()))

webbrowser.open(dst) 

IDLE does not like lines only space characters, so here safer version that works.

hello = dict(zip('helowrd'.upper(),'''
 *  *
 *  *
 ****
 *  *
 *  *

 ****
 *
 ****
 *
 ****

 *
 *
 *
 *
 ****

  ***
 *   *
 *   *
 *   *
  ***

*  *  *
*  *  *
*  *  *
 *  *

 ****
 *   *
 *  *
 ***
 *  *
 *   *

 ***
 *  *
 *  *
 *  *
 ***
'''.split('\n\n')))

hello[' '] = 5 * '\n'
print('\n\n'.join(hello[c] for c in 'Hello world'.upper()))

@pyTony, for some odd reason the '\n' only line does not copy and paste well on my Linux machine using IDLE, so I modified your clever code like this ...

''' hello_world_pytony1.py
use "\n~" as delimiter
'''

hello = dict(zip('helowrd'.upper(),'''
 *  *
 *  *
 ****
 *  *
 *  *
~
 ****
 *
 ****
 *
 ****
~
 *
 *
 *
 *
 ****
~
  ***
 *   *
 *   *
 *   *
  ***
~
*  *  *
*  *  *
*  *  *
 *  *
~
 ****
 *   *
 *  *
 ***
 *  *
 *   *
~
 ***
 *  *
 *  *
 *  *
 ***
'''.split('\n~')))

hello[' '] = 5 * '\n'
#print(hello)  # test
print('\n\n'.join(hello[c] for c in 'Hello world'.upper()))

Now it copies and pastes well.

Hi, double newlines seemed to work in Windows, but rotating the text turned out to be little more involved than I thought. I even had to revise my earlier rotation code to use izip_longest to deal with not square rotation of the character matrix.

try:
    from itertools import izip_longest
except ImportError:
    # Python 3
    from itertools import zip_longest as izip_longest

def rot_right(a, fillvalue=None):
    return list(izip_longest(*a[::-1], fillvalue=fillvalue))


hello = dict(zip('helowrd'.upper(),'''
 *  *
 *  *
 ****
 *  *
 *  *
§
 ****
 *
 ****
 *
 ****
§
 *
 *
 *
 *
 ****
§
  ***
 *   *
 *   *
 *   *
  ***
§
*  *  *
*  *  *
*  *  *
 *  *
§
 ****
 *   *
 *  *
 ***
 *  *
 *   *
§
 ***
 *  *
 *  *
 *  *
 ***
'''.split('\n§')))

hello[' '] = 5 * '     \n'
print('\n\n'.join(hello[c] for c in 'Hello world'.upper()))

print('Rotated:')
for c in 'Hello world'.upper():
    print('\n'.join(''.join(data)
                    for data in rot_right(hello[c].split('\n'),
                                          fillvalue=' ')
                    ))

@pyTony hi , I ran your code in python3 , it does not like izip_longest but it was fine with python2 . what should we use instead ?

I think in Python3 it is called zip_longest. I updated my code in original post.

@pyTony , hi , thank you for your codes . now I think it would be a great idea for this project to move 'hello world ' across the screen like an animated banner without using graphic packages
I have no idea how to do it so your help (anybody's help ) is appreciated .

@fonzali is this what you mean ? Click Here. Unfortunately, the code is unavailable ;). Let's rewrite it !

@Gribouillis hi , unfortunately youtube is filtered in my country
and I could not open it but after googling alot I found this instead .
http://usingpython.com/dl/animBanner.py
are there other ways of doing it ?

Here is my code changed to produce text mode banner effect by os independent way of printing empty lines for clearing the screen. This method suprizingly seems to work better for IDLE window than terminal (console) screen/window.

# -*- coding: cp1252 -*-
from __future__ import print_function
import time
try:
    from itertools import izip_longest
except ImportError:
    # Python 3
    from itertools import zip_longest as izip_longest

def rot_right(a, fillvalue=None):
    return list(izip_longest(*a[::-1], fillvalue=fillvalue))


hello = dict(zip('helowrd'.upper(),'''

 *  *
 *  *
 ****
 *  *
 *  *
§

 ****
 *
 ****
 *
 ****
§

 *
 *
 *
 *
 ****
§

  ***
 *   *
 *   *
 *   *
  ***
§

*  *  *
*  *  *
*  *  *
*  *  *
 *  *
§

 * *  
 *  *
 ***
 *  *
 *   *
§

 ***
 *  *
 *  *
 *  *
 ***
'''.split('\n§')))

hello[' '] = 5 * '     \n'
spacing = 10
# at least lines per terminal minus banner hight
# or less for multibanner effect
much = 25 - 6
banner_length = 80
banner = ['' for line in range(8)]
for c in 'Hello world'.upper():
    print(c)
    for n, line in enumerate(hello[c].split('\n')):
        print(n,line)
        banner[n] += line.ljust(spacing)
    n += 1
    while n < len(banner):
        banner[n] += ' '.ljust(spacing)
        n += 1


for rot in range(480):
    rot = rot % banner_length
    time.sleep(0.1)
    print('\n' * much) # system independant emptying of screen
    print('\n'.join((b[rot:] + spacing*' ' + b[:rot])[:banner_length] for b in banner))

@pyTony hi , again , thanks for the code . when I run it on idle I get two lines moving nicely and two other lines moving very very fast but these two fast lines do not show up when run in the terminal , I am guessing idle does not clear the screen fast enough

Using Java libraries with Jython ...

from javax.swing import JFrame

f = JFrame('Hello, World!')
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
f.setSize(300, 300)
f.setLocationRelativeTo(None)
f.setVisible(True)

Using Windows .NET or Linux Mono with IronPython ...

import clr

clr.AddReference("System.Windows.Forms")
clr.AddReference('System.Drawing')

from System.Windows.Forms import Application, Form
from System.Drawing import Color

class IForm(Form):

    def __init__(self):
        # set form title, bg_color, size, position
        self.Text = 'Hello World'
        self.BackColor = Color.Green
        self.Width = 250
        self.Height = 200
        self.CenterToScreen()

Application.Run(IForm())
# this will move 'hello world ' across the window horizontally
import time
import sys
if sys.version[0]=='3':
    from tkinter import *
else:
    from Tkinter import *

root = Tk()

canvas = Canvas(root, width=500, height=400)
canvas.pack()
txt=canvas.create_text(110,200,text='hello world', fill='Green',font=('Helvetica',30,'bold'))
y = x = 5

for k in range(50):
    time.sleep(0.15)
    canvas.move(txt, x,0)
    canvas.update()

root.mainloop()

please make this correction , line 14 should be

x=5

well , I am pretty sure people in Germany do not use "hello world" so here is my code translated to German (hallo welt)
and since I am using random , you will get different results

import time
import random
import sys
if sys.version[0]=='3':
    from tkinter import *
else:
    from Tkinter import *

root=Tk()
root.title('hello world in German')
canvas = Canvas(root,width=400, height=400, relief = RAISED,bg = 'blue')
canvas.pack()


txt2=canvas.create_text(100,300,text='hallo welt',fill='Yellow',font=('Helvetica',30,'bold'))

x1=random.randint(0,5)
y1=random.randint(0,5)
for x in range(50):
    canvas.move(txt2, x1, -y1)
    canvas.after(30)
    canvas.update()


root.mainloop()

A small improvement !

import time
import random
import sys
if sys.version[0]=='3':
    from tkinter import *
else:
    from Tkinter import *

root=Tk()
root.title('hello world in German')
canvas = Canvas(root,width=400, height=400, relief = RAISED,bg = 'blue')
canvas.pack()


txt2=canvas.create_text(100,300,text='hallo welt',fill='Yellow',font=('Helvetica',30,'bold'))


x1, y1 = (random.randint(1,6) for i in range(2))

while True:
    canvas.move(txt2, x1, y1)
    canvas.after(30)
    canvas.update()
    bl, bt, br, bb = canvas.bbox(txt2)
    if bl < 0 or br > 400 or bt < 0 or bb > 400:
        x1, y1 = (random.randint(1,6) for i in range(2))
    if bl < 0:
        x1 = abs(x1)
    elif br > 400:
        x1 = -abs(x1)
    if bt < 0:
        y1 = abs(y1)
    elif bb > 400:
        y1 = -abs(y1)

root.mainloop()
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.