会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132911个问题

from tkinter import *
from tkinter import messagebox


class Application(Frame):
    def __init__(self,master):
        Frame.__init__(self,master)
        self.master = master
        self.pack()
        self.creatWidget()

    def creatWidget(self):
        # 多行文本
        self.w1 = Text(root, width=40,height=12,bg='gray')
        self.w1.pack()
        self.w1.insert(1.0,'0123456789\nabcdefg')
        self.w1.insert(2.3, "锄禾日当午, 汗滴禾下土。 谁知盘中餐, 粒粒皆辛苦\n")

        # 重复插入文本按钮
        self.btn01 = Button(self,text='重复插入文本',command=self.insertText)
        self.btn01.pack(side='left')

        # 返回文本按钮
        self.btn02 = Button(self,text='返回文本',command=self.returnText)
        self.btn02.pack(side='left')

        # 添加图片按钮
        self.btn03 = Button(self,text='添加图片',command=self.addImage)
        self.btn03.pack(side='left')

        # 添加组件
        self.btn04 = Button(self,text='添加组件',command=self.addWidget)
        self.btn04.pack(side='left')


    def insertText(self):
        self.w1.insert(INSERT,'chenhaobang')
        self.w1.insert(END,'[bang]')
        self.w1.insert(1.8,'chen')

    def returnText(self):
        print(self.w1.get(1.2,1.6))

    def addImage(self):
        global photo
        photo = PhotoImage(file=r'D:\Python_Test\imgs_GUI\logo.gif')
        self.w1.image_create(END,image=photo)

    def addWidget(self):
        b1 = Button(self.w1, text='爱尚学堂')
        self.w1.window_create(INSERT, window=b1)

if __name__ == '__main__':
    root =Tk()
    root.geometry('500x400+200+200')
    app = Application(root)
    root.mainloop()

老师,你好

多次按下“添加图片”按钮后,只显示一张图片,这是什么原因呢

image.png


Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 21466楼
WEB前端全系列/第二阶段:JavaScript编程模块/函数与对象 21467楼


package com.bjsxt;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcTest {
	
	public void insertDepartment(String department_name, int location_id,float salary ){
		Connection con=null;
		Statement str=null;
		
		try {
			// con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test_2?useUnicode=true&characterEncoding=utf-8","root","root");
			con=jdbcUtil.getConnection();
			String sql="insert into department values(default,'"+department_name+"',"+location_id+","+salary+")";
			 str=con.createStatement();
			int flag=str.executeUpdate(sql);
			System.out.println(flag);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			jdbcUtil.closeResource(str, con);
			
		}
		
			
		
	}
	
	public static void updateDepartments(String department_name,int location_id,int department_id){
		 Connection con=null;
		 Statement str=null;
		 
		 try {
			Class.forName("com.mysql.jdbc.Driver");
			con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test_2?useUnicode=true&characterEncoding=utf-8","root","root");
			str=con.createStatement();
            String sql="UPDATE department d SET d.department_name='"+department_name+"',d.location_id="+location_id+" WHERE department_id="+department_id+"";
			int flag=str.executeUpdate(sql);
			System.out.println(flag); 
		} catch (ClassNotFoundException e) { 
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(str!=null){
				try {
					str.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			if(con!=null){
				try {
					con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		
		
	}
		 
		 
		 
		
		
	}
	
	
	
	public static void main(String[] args) {
		JdbcTest st=new JdbcTest();
		
		//st.insertDepartment("研发部",8,4500);
		//updateDepartments("教学楼",31,2);
		st.insertDepartment("学习部",9,4500);
		
	}
	
	

}




package com.bjsxt;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

import javax.sql.DataSource;

public class jdbcUtil {
		/*private  static String driver="com.mysql.jdbc.Driver";
		private static String url="jdbc:mysql://localhost/3306/test_2?useUnicode=true&characterEncoding=utf-8";
		private static String username="root";
		private static  String password="root";*/
		private  static String driver;
		private static String url;
		private static String username;
		private static  String password;
		private static DataSource ds;
		static {
			
			ResourceBundle bundle=ResourceBundle.getBundle("jdbc.properties");
			driver=bundle.getString("driver");
			url=bundle.getString("url");
			username=bundle.getString("username");
			password=bundle.getString("password");
			try {	
				Class.forName(driver);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
					
		}
		public static Connection getConnection(){
			
			Connection con=null;;
			try {
				con = DriverManager.getConnection(url, username, password);
			
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return con;
			
		
			
		}
		
		
		
		
		//关闭 statement;
		public static void closeStatement(Statement state){
			if(state!=null){
				try {
					state.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
				
			}
			
			
		}
		//关闭Connection 
		public static void closeConenection(Connection con){
			if(con!=null){
				try {
					con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
			}
			
			
			
		}
		
		public static void  closeResource(Statement str,Connection con){
			closeStatement(str);
			closeConenection(con);
			
			
		}
	

}




程序异常如下:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.bjsxt.jdbcUtil
	at com.bjsxt.JdbcTest.insertDepartment(JdbcTest.java:25)
	at com.bjsxt.JdbcTest.main(JdbcTest.java:86)


请问 老师 如何解决 ?

1.PNG





JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 21471楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        display:none;       隐藏自己,原位置不保留
        visibility:hidden;  隐藏自己,原位置保留
        opacity:0;          隐藏自己,原位置保留
        overflow:hidden;    溢出部分隐藏

     -->
     <style>
         .box{
             width: 200px;
             height: 200px;
             border: 5px solid red;
             /* overflow: hidden;
              */
         }
     </style>
</head>
<body>
   
    <div class="box">
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
        <p>hellohellohellohellohellohellohellohellohello</p>
    </div>
   
</body>
</html>

为什么我这的内容溢出右边了,视频里没有溢出右边

image.png

Python 全系列/第七阶段:网页编程基础/浮动与定位 21472楼
人工智能/第六阶段:机器学习-线性分类/逻辑回归 21473楼
Python 全系列/第五阶段:数据库编程/mysql介绍与环境安装 21474楼
Python 全系列/第五阶段:数据库编程/mysql的使用 21475楼
JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 21476楼
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 21479楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637