Minggu, 16 Februari 2025

Openfile pada Python tkinter

 membuat openfile pada python 







 

# importing everything from tkinter
from tkinter import *

from tkinter import filedialog as fd
from tkinter import messagebox as mb

# create gui window
Main_window = Tk()

# set the configuration
# of the window
Main_window.geometry("220x100")


# define a function
# for setting the new text
def btn_aksi():
path= fd.askopenfilename()
#info pada dialogbox
my_string_var.set(path)
    



# create a Button widget and attached
# with java function
btn_1 = Button(Main_window,
            text = "Open..",
            command = btn_aksi)



# create a StringVar class
my_string_var = StringVar()

# set the text
my_string_var.set("Silahkan open File")

# create a label widget
my_label = Label(Main_window,
                textvariable = my_string_var)

# place widgets into
# the gui window
btn_1.pack()
my_label.pack()

# Start the GUI
Main_window.mainloop()