Answers for "making gui in python"

4

create gui applications with python

from tkinter import *
import time
Student_forum=Tk()
Student_forum.title("student form")
Student_forum.geometry('390x400')

Roll_ask = Label(Student_forum,text="Roll Number")
Roll_ask.pack()
Roll = Entry()
Roll.pack()

name_ask = Label(Student_forum,text = "Name")
name_ask.pack()
Name = Entry(Student_forum)
Name.pack()

age_ask = Label(Student_forum,text = "Age")
age_ask.pack()
age = Entry()
age.pack()
def submit():
    if Roll.get() == "":
        error = Label(Student_forum,text = "Please fill Roll section roll section can't remain blank")
        error.pack()
    elif Name.get() == "":
        error2 = Label(Student_forum ,text="Please fill your name in name section it  can't e remain blank")

        error2.pack()
    elif age.get() == "":
        error3 = Label(Student_forum,text="fill age section first")
        error3.pack()
    else:
        get_data = open("student_details.txt","r")
        get_data2 = get_data.read()
        if Roll.get() in get_data2:
            Label2 = Label(Student_forum,text="You are already added in the list")
            Label2.pack()
        else:
            steps = "Your name is " + Name.get() + " and your age is " + age.get()

            submit_out = Label(Student_forum,text = steps)
            submit_out.pack()
            txt_file = open("student_details.txt","a+")
            txt_file.writelines(str(("Roll number="+Roll.get()+" Name= "+Name.get()+" Age="+age.get()+"n")))
            txt_file.close()
            do = Label(Student_forum,text="Now you are added in the list of students")
            do.pack()
            
def clear():
    Roll.delete(0,"end")
    Name.delete(0,"end")
    age.delete(0,"end")
Button1 = Button(Student_forum,text="Submit Form",command=submit)
Button1.pack()
Button2 = Button(Student_forum,text="Clear",command=clear)
Button2.pack()
    
Student_forum.mainloop()
Posted by: Guest on August-12-2021
5

tkinter tutorial

# check this code first.
from tkinter import *

app = Tk()
# The title of the project
app.title("The title of the project")
# The size of the window
app.geometry("400x400")

# Defining a funtion
def c():
    # Label
    m = Label(app, text="Text")
    m.pack()


# Button
l = Button(app, text="The text of the Butoon", command=c)
# Packing the Button
l.pack()
app.mainloop()
# Quick Note : 
# When you put a command you should not use parentheses
# l = Button(app, text="The text of the Butoon", command=c)
# l = Button(app, text="The text of the Butoon", command=c())
Posted by: Guest on November-22-2020
7

python basic gui

from tkinter import *


# def click func
def click():
    # Getting the text info as an int() & Error handling
    try:
        text_info_1 = float(text1.get())
        text_info_2 = float(text2.get())
    except Exception as e:
        text1.delete(0, END)
        text2.delete(0, END)
        text3.delete(0, END)
        text3.insert(0, f'Error: {e}')
        return
    # actual part of the func
    text3.delete(0, END)
    text3.insert(0, text_info_1 + text_info_2)

# Gui Config
root = Tk()
root.geometry('300x400')
root.title('Poop')

# The actual gui
label1 = Label(root, text='Write something!')
label1.pack()

spacing1 = Label(root)
spacing1.pack()

text1 = Entry(root)
text1.pack(ipadx=20)

spacing2 = Label(root, text='+')
spacing2.pack()

text2 = Entry(root)
text2.pack(ipadx=20)

spacing3 = Label(root)
spacing3.pack()

button = Button(root, text='Click me!', command=click)
button.pack()

spacing4 = Label(root)
spacing4.pack()

text3 = Entry(root)
text3.pack(ipadx=60)

# Making the gui run
root.mainloop()
Posted by: Guest on March-26-2021
1

python gui

# App python gui

import tkinter as tk
import webbrowser as wb


def Facebook():
    wb.open('facebook.com')


def Instagram():
    wb.open('instagram.com')


def Twitter():
    wb.open('twitter.com')


def Youtube():
    wb.open('youtube.com')


def Google():
    wb.open('google.com')


window = tk.Tk()
window.title('Browser')

google = tk.Button(window, text='Google', command=Google)
youtube = tk.Button(window, text='Youtube', bg='red', fg='white', command=Youtube)
twitter = tk.Button(window, text='Twitter', bg='powder blue', fg='white', command=Twitter)
Instagram = tk.Button(window, text='Instagram', bg='white', fg='black', command=Instagram)
facebook = tk.Button(window, text='Facebook', bg='blue', fg='white', command=Facebook)
facebook.pack()
Instagram.pack()
twitter.pack()
youtube.pack()
google.pack()

window.mainloop()
Posted by: Guest on November-07-2020
4

python gui

import tkinter as tk
#Importing the main module
window = tk.Tk()
window.mainloop()
Posted by: Guest on October-04-2020
0

gui in python

import pygame
pygame.init()
W, H = 900, 500
WIN = pygame.display.set_mode((W, H))
run = True
while run:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      run = False
pygame.quit()
Posted by: Guest on July-27-2021

Python Answers by Framework

Browse Popular Code Answers by Language